stzhao commited on
Commit
e00af04
·
verified ·
1 Parent(s): 51ce5b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -33
app.py CHANGED
@@ -270,55 +270,49 @@ def create_demo():
270
 
271
  with gr.Row():
272
  with gr.Column(scale=1):
273
- api_key = gr.Textbox(label="OpenAI API Key", value="sk-kBQuM0gvNBhOHmKz43b3iQut01bsOgg8Pv76eMKguu6jvncm")
274
  base_url = gr.Textbox(label="Base URL (optional)", value="https://api.claudeshop.top/v1")
275
  image_input = gr.Image(label="Upload Image", type="pil")
276
  question = gr.Textbox(label="Question", placeholder="Ask a question about the image...")
277
  submit_btn = gr.Button("Submit")
278
 
279
- # with gr.Column(scale=1):
280
- # json_output = gr.JSON(label="Messages JSON", visible=False)
281
-
282
  with gr.Row():
283
  output = gr.HTML(label="Response")
284
-
285
- # # 添加JSON下载功能
286
- # download_btn = gr.Button("Download Messages as JSON")
287
 
288
  # 处理提交
289
- result = submit_btn.click(
290
  fn=o3_chat,
291
  inputs=[api_key, base_url, question, image_input],
292
  outputs=[output]
293
  )
294
 
295
- # # 添加下载功能
296
- # download_btn.click(
297
- # fn=lambda x: x,
298
- # inputs=[json_output],
299
- # outputs=[],
300
- # _js="""
301
- # function(json_str) {
302
- # const blob = new Blob([JSON.stringify(json_str, null, 2)], { type: 'application/json' });
303
- # const url = URL.createObjectURL(blob);
304
- # const a = document.createElement('a');
305
- # a.href = url;
306
- # a.download = 'messages_' + new Date().toISOString().replace(/[:.]/g, '-') + '.json';
307
- # document.body.appendChild(a);
308
- # a.click();
309
- # document.body.removeChild(a);
310
- # URL.revokeObjectURL(url);
311
- # return [];
312
- # }
313
- # """
314
- # )
315
 
316
  gr.Markdown("""
317
- ## Examples
318
- Try asking questions like:
319
- - "What's in this image?"
320
- - "Can you analyze the data in this chart?"
321
- - "Generate a similar visualization with Python"
322
  """)
323
 
324
  return demo
 
270
 
271
  with gr.Row():
272
  with gr.Column(scale=1):
273
+ api_key = gr.Textbox(label="OpenAI API Key", type="password", value="sk-kBQuM0gvNBhOHmKz43b3iQut01bsOgg8Pv76eMKguu6jvncm")
274
  base_url = gr.Textbox(label="Base URL (optional)", value="https://api.claudeshop.top/v1")
275
  image_input = gr.Image(label="Upload Image", type="pil")
276
  question = gr.Textbox(label="Question", placeholder="Ask a question about the image...")
277
  submit_btn = gr.Button("Submit")
278
 
 
 
 
279
  with gr.Row():
280
  output = gr.HTML(label="Response")
 
 
 
281
 
282
  # 处理提交
283
+ submit_btn.click(
284
  fn=o3_chat,
285
  inputs=[api_key, base_url, question, image_input],
286
  outputs=[output]
287
  )
288
 
289
+ # 示例部分
290
+ examples = [
291
+ [
292
+ "./examples/1.png",
293
+ "From the information on that advertising board, what is the type of this shop?"
294
+ ],
295
+ [
296
+ "./examples/2.png",
297
+ "What is the diagnosis for the abnormality seen in this image?"
298
+ ]
299
+ ]
300
+
301
+ gr.Examples(
302
+ examples=examples,
303
+ inputs=[image_input, question],
304
+ outputs=[output],
305
+ fn=lambda img, q: o3_chat(api_key.value, base_url.value, q, img),
306
+ cache_examples=True,
307
+ label="Click any example to try it out!"
308
+ )
309
 
310
  gr.Markdown("""
311
+ ### Tips
312
+ 1. For best results, ask specific questions
313
+ 2. The system can execute Python code - ask for code implementations
314
+ 3. Try uploading different types of images (photos, charts, diagrams)
315
+ 4. You can ask follow-up questions about previous responses
316
  """)
317
 
318
  return demo