Commit
·
3c0c21d
1
Parent(s):
880071c
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,19 @@ def init_apis(openai_api_key, huggingface_api_key):
|
|
10 |
# 这个函数用于初始化OpenAI和Hugging Face API
|
11 |
openai.api_key = openai_api_key
|
12 |
headers["Authorization"] = f"Bearer {huggingface_api_key}"
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def query(url):
|
16 |
# 这个函数会向Hugging Face API发送图像URL,并获取图像中检测到的对象
|
@@ -21,10 +33,8 @@ def query(url):
|
|
21 |
api_response = requests.request("POST", API_URL, headers=headers, data=data)
|
22 |
return json.loads(api_response.content.decode("utf-8"))
|
23 |
|
24 |
-
def process_query(
|
25 |
-
|
26 |
-
|
27 |
-
print("Processing the image object detection task...")
|
28 |
function_descriptions = [
|
29 |
{
|
30 |
"name": "目标检测模型",
|
@@ -68,17 +78,16 @@ def process_query(openai_api_key, huggingface_api_key, user_query):
|
|
68 |
|
69 |
return second_response['choices'][0]['message']['content']
|
70 |
|
71 |
-
# Gradio
|
72 |
-
|
73 |
fn=process_query,
|
74 |
inputs=[
|
75 |
-
gr.inputs.Textbox(label="OpenAI Key", type="password"),
|
76 |
-
gr.inputs.Textbox(label="HuggingFace Key", type="password"),
|
77 |
gr.inputs.Textbox(label="Question")
|
78 |
],
|
79 |
outputs="text",
|
80 |
-
title="
|
81 |
-
description="Enter your
|
82 |
)
|
83 |
|
84 |
-
|
|
|
|
10 |
# 这个函数用于初始化OpenAI和Hugging Face API
|
11 |
openai.api_key = openai_api_key
|
12 |
headers["Authorization"] = f"Bearer {huggingface_api_key}"
|
13 |
+
return "APIs initialized successfully."
|
14 |
+
|
15 |
+
# 创建用于初始化API的Gradio接口
|
16 |
+
init_interface = gr.Interface(
|
17 |
+
fn=init_apis,
|
18 |
+
inputs=[
|
19 |
+
gr.inputs.Textbox(label="OpenAI Key", type="password"),
|
20 |
+
gr.inputs.Textbox(label="HuggingFace Key", type="password"),
|
21 |
+
],
|
22 |
+
outputs="text",
|
23 |
+
title="Initialize APIs",
|
24 |
+
description="Enter your OpenAI and Hugging Face API keys.",
|
25 |
+
)
|
26 |
|
27 |
def query(url):
|
28 |
# 这个函数会向Hugging Face API发送图像URL,并获取图像中检测到的对象
|
|
|
33 |
api_response = requests.request("POST", API_URL, headers=headers, data=data)
|
34 |
return json.loads(api_response.content.decode("utf-8"))
|
35 |
|
36 |
+
def process_query(user_query):
|
37 |
+
# 这个函数处理图像对象检测任务
|
|
|
|
|
38 |
function_descriptions = [
|
39 |
{
|
40 |
"name": "目标检测模型",
|
|
|
78 |
|
79 |
return second_response['choices'][0]['message']['content']
|
80 |
|
81 |
+
# 创建用于处理查询的Gradio接口
|
82 |
+
query_interface = gr.Interface(
|
83 |
fn=process_query,
|
84 |
inputs=[
|
|
|
|
|
85 |
gr.inputs.Textbox(label="Question")
|
86 |
],
|
87 |
outputs="text",
|
88 |
+
title="Process Query",
|
89 |
+
description="Enter your question. The model will return the detected objects in the image.",
|
90 |
)
|
91 |
|
92 |
+
init_interface.launch()
|
93 |
+
query_interface.launch()
|