Update app.py
Browse files
app.py
CHANGED
@@ -59,64 +59,65 @@ def ask_image(text,image,api_token=openai_api_key):
|
|
59 |
public_url = upload_image_to_gcs_blob(image)
|
60 |
print(text)
|
61 |
print(public_url)
|
62 |
-
print('-----------------------\n')
|
63 |
-
messages=[
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
]
|
78 |
|
79 |
-
# 请求头部信息
|
80 |
-
headers = {
|
81 |
-
|
82 |
-
}
|
83 |
|
84 |
-
# 请求体信息
|
85 |
-
data = {
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
}
|
90 |
|
91 |
|
92 |
-
# 设定最大重试次数
|
93 |
-
max_retry = 3
|
94 |
|
95 |
-
for i in range(max_retry):
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
120 |
|
121 |
|
122 |
# gradio demo
|
|
|
59 |
public_url = upload_image_to_gcs_blob(image)
|
60 |
print(text)
|
61 |
print(public_url)
|
62 |
+
# print('-----------------------\n')
|
63 |
+
# messages=[
|
64 |
+
# {
|
65 |
+
# "role": "user",
|
66 |
+
# "content": [
|
67 |
+
# {"type": "text", "text": text},
|
68 |
+
# {
|
69 |
+
# "type": "image_url",
|
70 |
+
# "image_url": {
|
71 |
+
# # "url":f"data:image/jpeg;base64,{base64_image}"
|
72 |
+
# "url": public_url
|
73 |
+
# },
|
74 |
+
# },
|
75 |
+
# ],
|
76 |
+
# }
|
77 |
+
# ]
|
78 |
|
79 |
+
# # 请求头部信息
|
80 |
+
# headers = {
|
81 |
+
# 'Authorization': f'Bearer {api_token}'
|
82 |
+
# }
|
83 |
|
84 |
+
# # 请求体信息
|
85 |
+
# data = {
|
86 |
+
# 'model': 'gpt-4o', # 可以根据需要更换其他模型
|
87 |
+
# 'messages': messages,
|
88 |
+
# 'temperature': 0.7 # 可以根据需要调整
|
89 |
+
# }
|
90 |
|
91 |
|
92 |
+
# # 设定最大重试次数
|
93 |
+
# max_retry = 3
|
94 |
|
95 |
+
# for i in range(max_retry):
|
96 |
+
# try:
|
97 |
+
# # 发送请求
|
98 |
+
# response = requests.post('https://burn.hair/v1/chat/completions', headers=headers, json=data)
|
99 |
|
100 |
+
# # 解析响应内容
|
101 |
+
# response_data = response.json()
|
102 |
+
# response_content = response_data['choices'][0]['message']['content']
|
103 |
+
# usage = response_data['usage']
|
104 |
|
105 |
+
# supabase_insert_ask_image(text,public_url,response_content)
|
106 |
+
# return response_content
|
107 |
|
108 |
+
# except Exception as e:
|
109 |
+
# # 如果已经达到最大重试次数,那么返回空值
|
110 |
+
# if i == max_retry - 1:
|
111 |
+
# print(f'重试次数已达上限,仍未能成功获取数据,错误信息:{e}')
|
112 |
+
# response_content = ''
|
113 |
+
# usage = {}
|
114 |
+
# return response_content
|
115 |
+
# else:
|
116 |
+
# # 如果未达到最大重试次数,打印错误信息,并继续下一次循环
|
117 |
+
# print(f'第{i+1}次请求失败,错误信息:{e},准备进行第{i+2}次尝试')
|
118 |
+
|
119 |
+
res = "**Important Announcement:** \n\nThis space is shutting down now. \n\nVisit [chatgpt-4o](https://chatgpt-4o.streamlit.app/) for an improved UI experience and future enhancements."
|
120 |
+
return res
|
121 |
|
122 |
|
123 |
# gradio demo
|