Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
from PIL import Image | |
# โหลดโมเดลและ pipeline | |
model, tokenizer = FastVisionModel.from_pretrained( | |
"unsloth/Llama-3.2-11B-Vision-Instruct", | |
load_in_4bit=True, | |
use_gradient_checkpointing="unsloth", | |
device_map="auto" | |
) | |
vision_pipeline = pipeline( | |
"image-to-text", | |
model=model, | |
tokenizer=tokenizer, | |
device=0 | |
) | |
# ฟังก์ชันสำหรับ Gradio | |
def analyze_image(image, instruction): | |
result = vision_pipeline(images=image, instruction=instruction, max_new_tokens=128) | |
return result[0]["generated_text"] | |
# สร้าง UI ด้วย Gradio | |
interface = gr.Interface( | |
fn=analyze_image, | |
inputs=[ | |
gr.Image(type="pil"), | |
gr.Textbox(label="Instruction", value="You are an expert radiographer. Describe accurately what you see in this image.") | |
], | |
outputs=gr.Textbox(label="Generated Text"), | |
title="Medical Image Analysis", | |
description="Analyze X-ray images and generate a diagnostic report." | |
) | |
# รันแอป | |
if __name__ == "__main__": | |
interface.launch() | |