Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import base64
|
4 |
-
from PIL import Image
|
5 |
-
import io
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
gr.Markdown("# 🌋 LLaVA Web Interface (Remote Inference)")
|
34 |
-
gr.Markdown("上传图片并输入文本,LLaVA 将在远程 GPU 服务器推理")
|
35 |
-
|
36 |
-
with gr.Row():
|
37 |
-
with gr.Column(scale=3):
|
38 |
-
image_input = gr.Image(type="pil", label="上传图片")
|
39 |
-
text_input = gr.Textbox(placeholder="输入文本...", label="输入文本")
|
40 |
-
submit_button = gr.Button("提交")
|
41 |
-
|
42 |
-
with gr.Column(scale=7):
|
43 |
-
chatbot_output = gr.Textbox(label="LLaVA 输出", interactive=False)
|
44 |
-
|
45 |
-
submit_button.click(fn=llava_infer, inputs=[image_input, text_input], outputs=chatbot_output)
|
46 |
-
|
47 |
-
# **启动 Hugging Face Web UI**
|
48 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
|
|
3 |
|
4 |
+
API_URL = "http://169.233.7.2/infer"
|
5 |
+
|
6 |
+
def process_image(image, text, conv_mode):
|
7 |
+
"""调用本地 API 进行推理"""
|
8 |
+
if image is None:
|
9 |
+
return "Please upload an image."
|
10 |
+
|
11 |
+
files = {"image": image}
|
12 |
+
data = {"text": text, "conv_mode": conv_mode}
|
13 |
+
|
14 |
+
response = requests.post(API_URL, files=files, json=data)
|
15 |
+
return response.json().get("response", "Error processing the image.")
|
16 |
+
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=process_image,
|
19 |
+
inputs=[
|
20 |
+
gr.Image(type="file"),
|
21 |
+
gr.Textbox(label="Prompt"),
|
22 |
+
gr.Dropdown(choices=["vicuna_v1", "llama3"], label="Conversation Mode")
|
23 |
+
],
|
24 |
+
outputs="text",
|
25 |
+
title="LLaVA Web Interface",
|
26 |
+
description="Upload an image and provide a prompt to interact with LLaVA."
|
27 |
+
)
|
28 |
+
|
29 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|