Yanqing0327 commited on
Commit
ade99a4
·
verified ·
1 Parent(s): a722746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import gradio as gr
2
  import requests
3
 
4
- # 你的 ngrok 地址(确保它正确)
5
- API_URL = "https://8725-169-233-7-2.ngrok-free.app/predict/"
6
 
7
  def chat(image, text):
8
- """调用本地 LLaVA 服务器的 API"""
9
  if image is None:
10
- return "请上传图片"
11
 
12
- # 保存图片为临时文件
13
  image.save("temp.jpg")
14
 
15
  files = {"image": open("temp.jpg", "rb")}
@@ -17,18 +17,18 @@ def chat(image, text):
17
 
18
  try:
19
  response = requests.post(API_URL, files=files, data=data)
20
- return response.json().get("response", "错误:无法解析响应")
21
  except Exception as e:
22
- return f"请求失败: {str(e)}"
23
 
24
- # 创建 Gradio 界面
25
  iface = gr.Interface(
26
  fn=chat,
27
- inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="输入你的问题")],
28
  outputs=gr.Textbox(),
29
  title="LLaVA Visual Chatbot",
30
- description="上传图片并输入问题,LLaVA 将回答你的问题。",
31
  )
32
 
33
- # 启动 Gradio
34
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  import requests
3
 
4
+ # Your ngrok URL (ensure it is correct)
5
+ API_URL = "https://0e8b-169-233-7-2.ngrok-free.app/predict/"
6
 
7
  def chat(image, text):
8
+ """Call the local LLaVA server API"""
9
  if image is None:
10
+ return "Please upload an image."
11
 
12
+ # Save the image as a temporary file
13
  image.save("temp.jpg")
14
 
15
  files = {"image": open("temp.jpg", "rb")}
 
17
 
18
  try:
19
  response = requests.post(API_URL, files=files, data=data)
20
+ return response.json().get("response", "Error: Unable to parse response.")
21
  except Exception as e:
22
+ return f"Request failed: {str(e)}"
23
 
24
+ # Create Gradio interface
25
  iface = gr.Interface(
26
  fn=chat,
27
+ inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question")],
28
  outputs=gr.Textbox(),
29
  title="LLaVA Visual Chatbot",
30
+ description="Upload an image and enter a question. LLaVA will provide an answer.",
31
  )
32
 
33
+ # Launch Gradio
34
  iface.launch(server_name="0.0.0.0", server_port=7860)