Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoModel, AutoProcessor
|
| 5 |
+
|
| 6 |
+
# Tải mô hình phân tích ảnh X-quang từ Google
|
| 7 |
+
model = AutoModel.from_pretrained("google/cxr-foundation")
|
| 8 |
+
processor = AutoProcessor.from_pretrained("google/cxr-foundation")
|
| 9 |
+
|
| 10 |
+
def du_doan_anh(image):
|
| 11 |
+
# Tiền xử lý ảnh
|
| 12 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
return "✅ AI đã phân tích ảnh.\n(Đây là mô hình biểu diễn đặc trưng, bạn có thể huấn luyện thêm.)"
|
| 16 |
+
|
| 17 |
+
# Tạo giao diện tiếng Việt
|
| 18 |
+
app = gr.Interface(
|
| 19 |
+
fn=du_doan_anh,
|
| 20 |
+
inputs=gr.Image(type="pil", label="📤 Chọn ảnh X-quang"),
|
| 21 |
+
outputs=gr.Textbox(label="🤖 Kết quả phân tích"),
|
| 22 |
+
title="Phân tích ảnh X-quang bằng AI",
|
| 23 |
+
description="Website thử nghiệm phân tích ảnh X-quang bằng mô hình AI huấn luyện sẵn."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
app.launch()
|