Spaces:
Runtime error
Runtime error
Download app.py from qbration21/compare_image_question_answer: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/qbration21/compare_image_question_answer/resolve/main/app.py
- Command line
-
hf download hf://spaces/qbration21/compare_image_question_answer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/qbration21/compare_image_question_answer/resolve/main/app.py
1.27 kB
| from typing import List | |
| import gradio as gr | |
| from PIL import Image | |
| from models import load_transformers | |
| from libs.model_list import model_list | |
| def multiple_image_captioning(input_img: Image.Image, question:str) -> List: | |
| results = [] | |
| for model_name, pretrained_paths in model_list.items(): | |
| for pretrained_path in pretrained_paths: | |
| try: | |
| process = load_transformers(name=model_name, model_pretrain=pretrained_path) | |
| if question == '': | |
| text = process.image_captioning(input_img) | |
| else: | |
| text = process.visual_question_answering(input_img) | |
| except Exception as e: | |
| text = str(e) | |
| results.append(text) | |
| return results | |
| question_text_Box = gr.Textbox(label="Question") | |
| outputs = [] | |
| for model_name, pretrained_paths in model_list.items(): | |
| for pretrained_path in pretrained_paths: | |
| outputs.append(gr.Textbox(label=model_name, info=pretrained_path)) | |
| demo = gr.Interface(fn=multiple_image_captioning, | |
| inputs=[gr.Image(type='pil'), question_text_Box], | |
| outputs=outputs, | |
| ) | |
| demo.launch() |