Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
import clipGPT
|
|
@@ -10,12 +8,7 @@ import difflib
|
|
| 10 |
import ViTCoAtt
|
| 11 |
from build_vocab import Vocabulary
|
| 12 |
|
| 13 |
-
|
| 14 |
-
img = Image.open(io.imread(image_path_or_url))
|
| 15 |
-
img = img.resize((80, 80)) # Adjust size as needed
|
| 16 |
-
buf = io.BytesIO()
|
| 17 |
-
img.save(buf, format='JPEG')
|
| 18 |
-
return buf.getvalue()
|
| 19 |
|
| 20 |
# Caption generation functions
|
| 21 |
def generate_caption_clipgpt(image):
|
|
@@ -37,14 +30,29 @@ with gr.Blocks() as demo:
|
|
| 37 |
gr.HTML("<h1 style='text-align: center;'>MedViT: A Vision Transformer-Driven Method for Generating Medical Reports π₯π€</h1>")
|
| 38 |
gr.HTML("<p style='text-align: center;'>You can generate captions by uploading an X-Ray and selecting a model of your choice below</p>")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention"], label="Select Model")
|
| 43 |
|
| 44 |
generate_button = gr.Button("Generate Caption")
|
| 45 |
|
| 46 |
-
|
| 47 |
|
|
|
|
| 48 |
|
| 49 |
def predict(img, model_name):
|
| 50 |
if model_name == "CLIP-GPT2":
|
|
@@ -59,6 +67,7 @@ with gr.Blocks() as demo:
|
|
| 59 |
|
| 60 |
# Event handlers
|
| 61 |
generate_button.click(predict, [image, model_choice], caption) # Trigger prediction on button click
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import clipGPT
|
|
|
|
| 8 |
import ViTCoAtt
|
| 9 |
from build_vocab import Vocabulary
|
| 10 |
|
| 11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Caption generation functions
|
| 14 |
def generate_caption_clipgpt(image):
|
|
|
|
| 30 |
gr.HTML("<h1 style='text-align: center;'>MedViT: A Vision Transformer-Driven Method for Generating Medical Reports π₯π€</h1>")
|
| 31 |
gr.HTML("<p style='text-align: center;'>You can generate captions by uploading an X-Ray and selecting a model of your choice below</p>")
|
| 32 |
|
| 33 |
+
|
| 34 |
+
with gr.Row():
|
| 35 |
+
sample_images = [
|
| 36 |
+
'https://imgur.com/W1pIr9b',
|
| 37 |
+
'https://imgur.com/MLJaWnf',
|
| 38 |
+
'https://imgur.com/6XymFW1',
|
| 39 |
+
'https://imgur.com/zdPjZZ1',
|
| 40 |
+
'https://imgur.com/DKUlZbF'
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
image = gr.Image(label="Upload Chest X-ray", type="pil")
|
| 45 |
+
|
| 46 |
+
sample_images_gallery = gr.Gallery(value = sample_images,label="Sample Images")
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention"], label="Select Model")
|
| 50 |
|
| 51 |
generate_button = gr.Button("Generate Caption")
|
| 52 |
|
| 53 |
+
|
| 54 |
|
| 55 |
+
caption = gr.Textbox(label="Generated Caption")
|
| 56 |
|
| 57 |
def predict(img, model_name):
|
| 58 |
if model_name == "CLIP-GPT2":
|
|
|
|
| 67 |
|
| 68 |
# Event handlers
|
| 69 |
generate_button.click(predict, [image, model_choice], caption) # Trigger prediction on button click
|
| 70 |
+
sample_images_gallery.change(predict, [sample_images_gallery, model_choice], caption) # Handle sample images
|
| 71 |
|
| 72 |
|
| 73 |
demo.launch()
|