Update app.py
Browse files
app.py
CHANGED
|
@@ -42,8 +42,24 @@ def upload_image_to_gcs_blob(image):
|
|
| 42 |
return public_url
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def ask_image(text,image,api_token=openai_api_key):
|
| 46 |
public_url = upload_image_to_gcs_blob(image)
|
|
|
|
|
|
|
|
|
|
| 47 |
messages=[
|
| 48 |
{
|
| 49 |
"role": "user",
|
|
@@ -101,11 +117,13 @@ def ask_image(text,image,api_token=openai_api_key):
|
|
| 101 |
# 如果未达到最大重试次数,打印错误信息,并继续下一次循环
|
| 102 |
print(f'第{i+1}次请求失败,错误信息:{e},准备进行第{i+2}次尝试')
|
| 103 |
|
|
|
|
|
|
|
| 104 |
|
| 105 |
# gradio demo
|
| 106 |
|
| 107 |
title = "Ask Image"
|
| 108 |
-
description = "Ask anything about your Image"
|
| 109 |
|
| 110 |
demo = gr.Interface(
|
| 111 |
fn=ask_image,
|
|
|
|
| 42 |
return public_url
|
| 43 |
|
| 44 |
|
| 45 |
+
def get_supabase_client():
|
| 46 |
+
url = os.environ.get('supabase_url')
|
| 47 |
+
key = os.environ.get('supbase_key')
|
| 48 |
+
supabase = create_client(url, key)
|
| 49 |
+
return supabase
|
| 50 |
+
|
| 51 |
+
def supabase_insert_ask_image(question,image,response_content):
|
| 52 |
+
supabase = get_supabase_client()
|
| 53 |
+
data, count = supabase.table('ask_image').insert({"question": question, "image": image,"response_content":response_content}).execute()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
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 |
"role": "user",
|
|
|
|
| 117 |
# 如果未达到最大重试次数,打印错误信息,并继续下一次循环
|
| 118 |
print(f'第{i+1}次请求失败,错误信息:{e},准备进行第{i+2}次尝试')
|
| 119 |
|
| 120 |
+
supabase_insert_ask_image(text,public_url,response_content)
|
| 121 |
+
|
| 122 |
|
| 123 |
# gradio demo
|
| 124 |
|
| 125 |
title = "Ask Image"
|
| 126 |
+
description = "Ask anything about your Image with GPT-4o"
|
| 127 |
|
| 128 |
demo = gr.Interface(
|
| 129 |
fn=ask_image,
|