SkalskiP commited on
Commit
fc7864f
1 Parent(s): 9fdba0a

Show error to user

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -38,6 +38,7 @@ def user(text_prompt: str, chatbot: List[Tuple[str, str]]):
38
  def bot(
39
  google_key: str,
40
  image_prompt: Optional[Image.Image],
 
41
  temperature: float,
42
  max_output_tokens: int,
43
  stop_sequences: str,
@@ -59,7 +60,7 @@ def bot(
59
  top_k=top_k,
60
  top_p=top_p)
61
 
62
- if image_prompt is None:
63
  model = genai.GenerativeModel('gemini-pro')
64
  response = model.generate_content(
65
  text_prompt,
@@ -67,9 +68,11 @@ def bot(
67
  generation_config=generation_config)
68
  response.resolve()
69
  else:
 
 
70
  model = genai.GenerativeModel('gemini-pro-vision')
71
  response = model.generate_content(
72
- [text_prompt, image_prompt],
73
  stream=True,
74
  generation_config=generation_config)
75
  response.resolve()
@@ -92,7 +95,8 @@ google_key_component = gr.Textbox(
92
  info="You have to provide your own GOOGLE_API_KEY for this app to function properly",
93
  )
94
 
95
- image_prompt_component = gr.Image(type="pil", label="Image", scale=1)
 
96
  chatbot_component = gr.Chatbot(
97
  label='Gemini',
98
  bubble_full_width=False,
@@ -170,6 +174,7 @@ user_inputs = [
170
  bot_inputs = [
171
  google_key_component,
172
  image_prompt_component,
 
173
  temperature_component,
174
  max_output_tokens_component,
175
  stop_sequences_component,
@@ -185,7 +190,10 @@ with gr.Blocks() as demo:
185
  with gr.Column():
186
  google_key_component.render()
187
  with gr.Row():
188
- image_prompt_component.render()
 
 
 
189
  chatbot_component.render()
190
  text_prompt_component.render()
191
  run_button_component.render()
@@ -215,4 +223,4 @@ with gr.Blocks() as demo:
215
  fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
216
  )
217
 
218
- demo.queue(max_size=99).launch(debug=True)
 
38
  def bot(
39
  google_key: str,
40
  image_prompt: Optional[Image.Image],
41
+ image_prompt_2: Optional[Image.Image],
42
  temperature: float,
43
  max_output_tokens: int,
44
  stop_sequences: str,
 
60
  top_k=top_k,
61
  top_p=top_p)
62
 
63
+ if image_prompt is None and image_prompt_2 is None:
64
  model = genai.GenerativeModel('gemini-pro')
65
  response = model.generate_content(
66
  text_prompt,
 
68
  generation_config=generation_config)
69
  response.resolve()
70
  else:
71
+ contents = [text_prompt, image_prompt, image_prompt_2]
72
+ contents = [content for content in contents if content is not None]
73
  model = genai.GenerativeModel('gemini-pro-vision')
74
  response = model.generate_content(
75
+ contents=contents,
76
  stream=True,
77
  generation_config=generation_config)
78
  response.resolve()
 
95
  info="You have to provide your own GOOGLE_API_KEY for this app to function properly",
96
  )
97
 
98
+ image_prompt_component = gr.Image(type="pil", label="Image")
99
+ image_prompt_2_component = gr.Image(type="pil", label="Image")
100
  chatbot_component = gr.Chatbot(
101
  label='Gemini',
102
  bubble_full_width=False,
 
174
  bot_inputs = [
175
  google_key_component,
176
  image_prompt_component,
177
+ image_prompt_2_component,
178
  temperature_component,
179
  max_output_tokens_component,
180
  stop_sequences_component,
 
190
  with gr.Column():
191
  google_key_component.render()
192
  with gr.Row():
193
+ with gr.Column(scale=1):
194
+ image_prompt_component.render()
195
+ with gr.Accordion("Multi Image", open=False):
196
+ image_prompt_2_component.render()
197
  chatbot_component.render()
198
  text_prompt_component.render()
199
  run_button_component.render()
 
223
  fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
224
  )
225
 
226
+ demo.queue(max_size=99).launch(debug=False, show_error=True)