fffiloni commited on
Commit
ec771a2
1 Parent(s): 8d15222

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -8,7 +8,7 @@ from gradio_client import Client
8
  #fuyu_client = Client("https://adept-fuyu-8b-demo.hf.space/")
9
  kosmos2_client = Client("https://ydshieh-kosmos-2.hf.space/")
10
 
11
- def get_caption(image_in):
12
  """
13
  fuyu_result = fuyu_client.predict(
14
  image_in, # str representing input in 'raw_image' Image component
@@ -106,11 +106,12 @@ Here's another example. If a user types, "In the image, there is a drawing of a
106
  return outputs
107
 
108
 
109
- def infer(image_in):
110
  gr.Info("Getting image description...")
111
- user_prompt = get_caption_from_MD(image_in)
112
-
113
-
 
114
 
115
  gr.Info("Building a system according to the image caption ...")
116
  outputs = get_llm_idea(user_prompt)
@@ -148,6 +149,14 @@ with gr.Blocks(css=css) as demo:
148
  type = "filepath",
149
  elem_id = "image-in"
150
  )
 
 
 
 
 
 
 
 
151
  submit_btn = gr.Button("Make LLM system from my pic !")
152
  with gr.Column():
153
  caption = gr.Textbox(
@@ -172,15 +181,14 @@ with gr.Blocks(css=css) as demo:
172
  ["examples/chicken_adobo.jpeg"]
173
  ],
174
  fn = infer,
175
- inputs = [image_in],
176
- outputs = [caption, result],
177
- cache_examples = False
178
  )
179
 
180
  submit_btn.click(
181
  fn = infer,
182
  inputs = [
183
- image_in
 
184
  ],
185
  outputs =[
186
  caption,
@@ -188,4 +196,4 @@ with gr.Blocks(css=css) as demo:
188
  ]
189
  )
190
 
191
- demo.queue().launch(show_api=False)
 
8
  #fuyu_client = Client("https://adept-fuyu-8b-demo.hf.space/")
9
  kosmos2_client = Client("https://ydshieh-kosmos-2.hf.space/")
10
 
11
+ def get_caption_from_kosmos(image_in):
12
  """
13
  fuyu_result = fuyu_client.predict(
14
  image_in, # str representing input in 'raw_image' Image component
 
106
  return outputs
107
 
108
 
109
+ def infer(image_in, cap_type):
110
  gr.Info("Getting image description...")
111
+ if cap_type == "Fictional" :
112
+ user_prompt = get_caption_from_MD(image_in)
113
+ elif cap_type == "Literal" :
114
+ user_prompt = get_caption_from_kosmos(image_in)
115
 
116
  gr.Info("Building a system according to the image caption ...")
117
  outputs = get_llm_idea(user_prompt)
 
149
  type = "filepath",
150
  elem_id = "image-in"
151
  )
152
+ cap_type = gr.Radio(
153
+ label = "Caption type",
154
+ choices = [
155
+ "Literal",
156
+ "Fictional"
157
+ ],
158
+ value = "Fictional"
159
+ )
160
  submit_btn = gr.Button("Make LLM system from my pic !")
161
  with gr.Column():
162
  caption = gr.Textbox(
 
181
  ["examples/chicken_adobo.jpeg"]
182
  ],
183
  fn = infer,
184
+ inputs = [image_in, cap_type]
 
 
185
  )
186
 
187
  submit_btn.click(
188
  fn = infer,
189
  inputs = [
190
+ image_in,
191
+ cap_type
192
  ],
193
  outputs =[
194
  caption,
 
196
  ]
197
  )
198
 
199
+ demo.queue().launch(show_api=False, show_error=True)