Spaces:
Runtime error
Runtime error
add hg login
Browse files
app.py
CHANGED
|
@@ -46,12 +46,12 @@ def is_image(file_path):
|
|
| 46 |
except IOError:
|
| 47 |
return False
|
| 48 |
|
| 49 |
-
def supbase_insert(user_message,response_content,messages,response):
|
| 50 |
from supabase import create_client, Client
|
| 51 |
url = os.environ.get('supabase_url')
|
| 52 |
key = os.environ.get('supbase_key')
|
| 53 |
supabase = create_client(url, key)
|
| 54 |
-
data, count = supabase.table('messages').insert({"user_message": user_message, "response_content": response_content,"messages":messages,"response":response}).execute()
|
| 55 |
|
| 56 |
|
| 57 |
# def respond(
|
|
@@ -86,7 +86,16 @@ def supbase_insert(user_message,response_content,messages,response):
|
|
| 86 |
# response += token
|
| 87 |
# yield response
|
| 88 |
|
| 89 |
-
def get_completion(message,history):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if message["text"].strip() == "" and not message["files"]:
|
| 91 |
raise gr.Error("Please input a query and optionally image(s).")
|
| 92 |
|
|
@@ -161,7 +170,7 @@ def get_completion(message,history):
|
|
| 161 |
response_content = response_data['choices'][0]['message']['content']
|
| 162 |
usage = response_data['usage']
|
| 163 |
|
| 164 |
-
supbase_insert(user_message,response_content,messages,response_data)
|
| 165 |
|
| 166 |
return response_content
|
| 167 |
|
|
@@ -174,17 +183,25 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 174 |
title = "ChatGPT-4o"
|
| 175 |
description = "This is GPT-4o, you can use the text and image capabilities now. More capabilities like audio and video will be rolled out iteratively in the future. Stay tuned."
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
demo.queue(default_concurrency_limit=5)
|
| 190 |
|
|
|
|
| 46 |
except IOError:
|
| 47 |
return False
|
| 48 |
|
| 49 |
+
def supbase_insert(user_message,response_content,messages,response,user_name,user_oauth_token):
|
| 50 |
from supabase import create_client, Client
|
| 51 |
url = os.environ.get('supabase_url')
|
| 52 |
key = os.environ.get('supbase_key')
|
| 53 |
supabase = create_client(url, key)
|
| 54 |
+
data, count = supabase.table('messages').insert({"user_message": user_message, "response_content": response_content,"messages":messages,"response":response,"user_name":user_name,"user_oauth_token":user_oauth_token}).execute()
|
| 55 |
|
| 56 |
|
| 57 |
# def respond(
|
|
|
|
| 86 |
# response += token
|
| 87 |
# yield response
|
| 88 |
|
| 89 |
+
def get_completion(message,history,profile: gr.OAuthProfile | None,oauth_token: gr.OAuthToken | None):
|
| 90 |
+
# check login
|
| 91 |
+
if profile is None:
|
| 92 |
+
raise gr.Error('Click "Sign in with Hugging Face" to continue')
|
| 93 |
+
|
| 94 |
+
user_name = profile.username
|
| 95 |
+
user_oauth_token = oauth_token.token
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# check if messages are empty
|
| 99 |
if message["text"].strip() == "" and not message["files"]:
|
| 100 |
raise gr.Error("Please input a query and optionally image(s).")
|
| 101 |
|
|
|
|
| 170 |
response_content = response_data['choices'][0]['message']['content']
|
| 171 |
usage = response_data['usage']
|
| 172 |
|
| 173 |
+
supbase_insert(user_message,response_content,messages,response_data,user_name,user_oauth_token)
|
| 174 |
|
| 175 |
return response_content
|
| 176 |
|
|
|
|
| 183 |
title = "ChatGPT-4o"
|
| 184 |
description = "This is GPT-4o, you can use the text and image capabilities now. More capabilities like audio and video will be rolled out iteratively in the future. Stay tuned."
|
| 185 |
|
| 186 |
+
|
| 187 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 188 |
+
gr.Markdown(
|
| 189 |
+
"# ChatGPT-4o"
|
| 190 |
+
"\n\nThis is GPT-4o, you can use the text and image capabilities now. More capabilities like audio and video will be rolled out iteratively in the future. Stay tuned."
|
| 191 |
+
)
|
| 192 |
+
gr.LoginButton()
|
| 193 |
+
|
| 194 |
+
gr.ChatInterface(
|
| 195 |
+
get_completion,
|
| 196 |
+
multimodal=True,
|
| 197 |
+
# title = title,
|
| 198 |
+
# description = description
|
| 199 |
+
# additional_inputs=[
|
| 200 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 201 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 202 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 203 |
+
# ],
|
| 204 |
+
)
|
| 205 |
|
| 206 |
demo.queue(default_concurrency_limit=5)
|
| 207 |
|