Spaces:
Runtime error
Runtime error
| #app.py | |
| import os | |
| import gradio as gr | |
| from gradio_client import Client | |
| from gradio_client.client import Job | |
| def vqa_fuyu(image_path: str, question: str, return_job: bool = False) -> str | Job: | |
| try: | |
| client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/9kcqv/") | |
| fn = client.submit if return_job else client.predict | |
| return fn(image_path, question, fn_index=3) | |
| except Exception: | |
| gr.Warning("The Fuyu-8B Space is currently unavailable. Please try again later.") | |
| return "" | |
| def answer_question(image_path: str, question:str) -> tuple[str]: | |
| jobs = [ | |
| vqa_fuyu(image_path, question, return_job=True), | |
| ] | |
| return tuple(job.result() if job else "" for job in jobs) | |
| def ask(q): | |
| return q | |
| with gr.Blocks(css="style.css") as demo: | |
| gr.Markdown(DESCRIPTION) | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_image = gr.Image(type="filepath") | |
| text_input = gr.Interface(fn=ask, inputs="text", outputs="text") | |
| run_button = gr.Button("ask question") | |
| with gr.Column(): | |
| out_fuyu = gr.Textbox(label="Fuyu-8B") | |
| outputs = [ | |
| out_fuyu, | |
| ] | |
| run_button.click( | |
| fn=answer_question, | |
| inputs=[input_image,text_input], | |
| outputs=outputs, | |
| api_name="vqa", | |
| ) | |
| if __name__ == "__main__": | |
| demo.queue(max_size=20).launch() |