Hank20041016 commited on
Commit
a822033
·
verified ·
1 Parent(s): b09bb1d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install transformers torch gradio pillow --quiet
2
+
3
+
4
+ from transformers import pipeline
5
+
6
+ pipe = pipeline("image-text-to-text", model="google/medgemma-4b-it")
7
+
8
+ messages = [
9
+ {
10
+ "role": "user",
11
+ "content": [
12
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
13
+ {"type": "text", "text": "What animal is on the candy?"}
14
+ ]
15
+ },
16
+ ]
17
+
18
+ result = pipe(text=messages)
19
+ print(result[0]["generated_text"])
20
+
21
+ # 建立 Gradio UI
22
+ iface = gr.Interface(
23
+ fn=predict,
24
+ inputs=["text", "text"], # image_url, question
25
+ outputs="text",
26
+ title="MedGemma Demo",
27
+ description="Input an image URL and a question to get MedGemma's answer."
28
+ )
29
+
30
+ iface.launch()