tlodato commited on
Commit
0e3225c
·
1 Parent(s): d51dc3e

start again

Browse files
Files changed (1) hide show
  1. app.py +8 -43
app.py CHANGED
@@ -1,47 +1,12 @@
1
  #app.py
2
- import os
3
  import gradio as gr
4
  from gradio_client import Client
5
- from gradio_client.client import Job
6
-
7
- def vqa_fuyu(image_path: str, question: str, return_job: bool = False) -> str | Job:
8
- try:
9
- client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/9kcqv/")
10
- fn = client.submit if return_job else client.predict
11
- return fn(image_path, question, fn_index=3)
12
- except Exception:
13
- gr.Warning("The Fuyu-8B Space is currently unavailable. Please try again later.")
14
- return ""
15
-
16
- def answer_question(image_path: str, question:str) -> tuple[str]:
17
- jobs = [
18
- vqa_fuyu(image_path, question, return_job=True),
19
- ]
20
- return tuple(job.result() if job else "" for job in jobs)
21
-
22
- def ask(q):
23
- return q
24
-
25
- with gr.Blocks(css="style.css") as demo:
26
- gr.Markdown("# Comparing VQA on image perturbation (rotation)")
27
- with gr.Row():
28
- with gr.Column():
29
- input_image = gr.Image(type="filepath")
30
- text_input = gr.Interface(fn=ask, inputs="text", outputs="text")
31
- run_button = gr.Button("ask question")
32
- with gr.Column():
33
- out_fuyu = gr.Textbox(label="Fuyu-8B")
34
-
35
- outputs = [
36
- out_fuyu,
37
- ]
38
-
39
- run_button.click(
40
- fn=answer_question,
41
- inputs=[input_image,text_input],
42
- outputs=outputs,
43
- api_name="vqa",
44
- )
45
 
46
- if __name__ == "__main__":
47
- demo.queue(max_size=20).launch()
 
 
 
 
 
 
1
  #app.py
2
+
3
  import gradio as gr
4
  from gradio_client import Client
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/9kcqv/")
7
+ result = client.predict(
8
+ "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath on your computer (or URL) of image) in 'Upload your Image' Image component
9
+ "Howdy!", # str in 'Ask a Question' Textbox component
10
+ fn_index=3
11
+ )
12
+ print(result)