simonlee-cb commited on
Commit
9e6acd9
·
1 Parent(s): ad3aed5

feat: added examples

Browse files
gradio_app.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import gradio_demo
3
+ import gradio_chat
4
+
5
+ with gr.Blocks() as demo:
6
+ gradio_chat.demo.render()
7
+ with demo.route("PicEdit"):
8
+ gradio_demo.demo.render()
9
+
10
+ if __name__ == "__main__":
11
+ demo.launch()
gradio_chat.py CHANGED
@@ -66,6 +66,10 @@ def build_messages_for_agent(chat_input, past_messages):
66
 
67
  return messages
68
 
 
 
 
 
69
 
70
  async def stream_from_agent(chat_input, chatbot, past_messages, current_image):
71
  # Prepare messages for the UI
@@ -172,10 +176,38 @@ with gr.Blocks() as demo:
172
  current_image = gr.State(None)
173
  past_messages = gr.State([])
174
  chatbot = gr.Chatbot(
 
175
  label='Image Editing Assistant',
176
  type='messages',
177
  avatar_images=(None, 'https://ai.pydantic.dev/img/logo-white.svg'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  )
 
179
  with gr.Row():
180
  chat_input = gr.MultimodalTextbox(
181
  interactive=True,
@@ -190,5 +222,15 @@ with gr.Blocks() as demo:
190
  outputs=[chat_input, chatbot, past_messages, current_image],
191
  )
192
 
 
 
 
 
 
 
 
 
 
 
193
  if __name__ == '__main__':
194
  demo.launch()
 
66
 
67
  return messages
68
 
69
+ def select_example(x: gr.SelectData, chat_input):
70
+ chat_input["text"] = x.value["text"]
71
+ chat_input["files"] = x.value["files"]
72
+ return chat_input
73
 
74
  async def stream_from_agent(chat_input, chatbot, past_messages, current_image):
75
  # Prepare messages for the UI
 
176
  current_image = gr.State(None)
177
  past_messages = gr.State([])
178
  chatbot = gr.Chatbot(
179
+ elem_id="chatbot",
180
  label='Image Editing Assistant',
181
  type='messages',
182
  avatar_images=(None, 'https://ai.pydantic.dev/img/logo-white.svg'),
183
+ examples=[
184
+ {
185
+ "text": "Remove the person in the image",
186
+ "files": [
187
+ "https://www.apple.com/tv-pr/articles/2024/10/apple-tv-unveils-severance-season-two-teaser-ahead-of-the-highly-anticipated-return-of-the-emmy-and-peabody-award-winning-phenomenon/images/big-image/big-image-01/1023024_Severance_Season_Two_Official_Trailer_Big_Image_01_big_image_post.jpg.large_2x.jpg"
188
+ ]
189
+ },
190
+ {
191
+ "text": "Change all the balloons to red in the image",
192
+ "files": [
193
+ "https://www.apple.com/tv-pr/articles/2024/10/apple-tv-unveils-severance-season-two-teaser-ahead-of-the-highly-anticipated-return-of-the-emmy-and-peabody-award-winning-phenomenon/images/big-image/big-image-01/1023024_Severance_Season_Two_Official_Trailer_Big_Image_01_big_image_post.jpg.large_2x.jpg"
194
+ ]
195
+ },
196
+ {
197
+ "text": "Change coffee to a glass of water",
198
+ "files": [
199
+ "https://previews.123rf.com/images/vadymvdrobot/vadymvdrobot1812/vadymvdrobot181201149/113217373-image-of-smiling-woman-holding-takeaway-coffee-in-paper-cup-and-taking-selfie-while-walking-through.jpg"
200
+ ]
201
+ },
202
+ {
203
+ "text": "ENHANCE!",
204
+ "files": [
205
+ "https://m.media-amazon.com/images/M/MV5BNzM3ODc5NzEtNzJkOC00MDM4LWI0MTYtZTkyNmY3ZTBhYzkxXkEyXkFqcGc@._V1_QL75_UX1000_CR0,52,1000,563_.jpg"
206
+ ]
207
+ }
208
+ ]
209
  )
210
+
211
  with gr.Row():
212
  chat_input = gr.MultimodalTextbox(
213
  interactive=True,
 
222
  outputs=[chat_input, chatbot, past_messages, current_image],
223
  )
224
 
225
+ chatbot.example_select(
226
+ select_example,
227
+ inputs=[chat_input],
228
+ outputs=[chat_input],
229
+ ).then(
230
+ stream_from_agent,
231
+ inputs=[chat_input, chatbot, past_messages, current_image],
232
+ outputs=[chat_input, chatbot, past_messages, current_image],
233
+ )
234
+
235
  if __name__ == '__main__':
236
  demo.launch()
src/agents/mask_generation_agent.py CHANGED
@@ -98,7 +98,9 @@ async def super_resolution(ctx: RunContext[ImageEditDeps]) -> EditImageResult:
98
  image_url = ctx.deps.image_url
99
  hopter_client = ctx.deps.hopter_client
100
 
101
- input = SuperResolutionInput(image_b64=image_url, scale=4, use_face_enhancement=False)
 
 
102
  result = hopter_client.super_resolution(input)
103
  uploaded_image = upload_image_from_base64(result.scaled_image)
104
  return EditImageResult(edited_image_url=uploaded_image)
 
98
  image_url = ctx.deps.image_url
99
  hopter_client = ctx.deps.hopter_client
100
 
101
+ image_uri = download_image_to_data_uri(image_url)
102
+
103
+ input = SuperResolutionInput(image_b64=image_uri, scale=4, use_face_enhancement=False)
104
  result = hopter_client.super_resolution(input)
105
  uploaded_image = upload_image_from_base64(result.scaled_image)
106
  return EditImageResult(edited_image_url=uploaded_image)