Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Set up password
|
| 6 |
username = os.getenv('username')
|
|
@@ -26,20 +28,24 @@ def chat_with_assistant(message, history):
|
|
| 26 |
role="user",
|
| 27 |
content=message
|
| 28 |
)
|
| 29 |
-
|
| 30 |
-
# Run the assistant
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
stream=True
|
| 35 |
)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
if
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Custom CSS for chat bubbles and colors
|
| 45 |
custom_css = """
|
|
@@ -49,7 +55,7 @@ custom_css = """
|
|
| 49 |
|
| 50 |
# Create the Gradio interface
|
| 51 |
with gr.Blocks(css=custom_css) as demo:
|
| 52 |
-
gr.HTML(f"""<img src
|
| 53 |
gr.Markdown("# **Learning Scales Assistant**🐬")
|
| 54 |
chatbot = gr.Chatbot(
|
| 55 |
[],
|
|
@@ -67,14 +73,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 67 |
|
| 68 |
def bot(history):
|
| 69 |
user_message = history[-1][0]
|
| 70 |
-
bot_message =
|
| 71 |
-
|
| 72 |
-
history[-1][1] = response_text
|
| 73 |
-
chatbot.update(history)
|
| 74 |
return history
|
| 75 |
|
| 76 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 77 |
bot, chatbot, chatbot
|
| 78 |
)
|
|
|
|
| 79 |
|
| 80 |
demo.launch(auth=(username, password))
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
+
import time
|
| 5 |
+
from ftr import warn
|
| 6 |
|
| 7 |
# Set up password
|
| 8 |
username = os.getenv('username')
|
|
|
|
| 28 |
role="user",
|
| 29 |
content=message
|
| 30 |
)
|
| 31 |
+
|
| 32 |
+
# Run the assistant
|
| 33 |
+
run = client.beta.threads.runs.create(
|
| 34 |
+
thread_id=thread.id,
|
| 35 |
+
assistant_id=assistant_id
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
+
# Wait for the assistant's response
|
| 39 |
+
while True:
|
| 40 |
+
run_status = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
|
| 41 |
+
if run_status.status == 'completed':
|
| 42 |
+
# Retrieve the assistant's response
|
| 43 |
+
messages = client.beta.threads.messages.list(thread_id=thread.id)
|
| 44 |
+
assistant_response = messages.data[0].content[0].text.value
|
| 45 |
+
break
|
| 46 |
+
time.sleep(1)
|
| 47 |
+
|
| 48 |
+
return assistant_response
|
| 49 |
|
| 50 |
# Custom CSS for chat bubbles and colors
|
| 51 |
custom_css = """
|
|
|
|
| 55 |
|
| 56 |
# Create the Gradio interface
|
| 57 |
with gr.Blocks(css=custom_css) as demo:
|
| 58 |
+
gr.HTML(f"""<img src="https://i.postimg.cc/L6mbcC7F/DASH.png" width="150" height="112">""")
|
| 59 |
gr.Markdown("# **Learning Scales Assistant**🐬")
|
| 60 |
chatbot = gr.Chatbot(
|
| 61 |
[],
|
|
|
|
| 73 |
|
| 74 |
def bot(history):
|
| 75 |
user_message = history[-1][0]
|
| 76 |
+
bot_message = chat_with_assistant(user_message, history)
|
| 77 |
+
history[-1][1] = bot_message
|
|
|
|
|
|
|
| 78 |
return history
|
| 79 |
|
| 80 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 81 |
bot, chatbot, chatbot
|
| 82 |
)
|
| 83 |
+
gr.Markdown(warn)
|
| 84 |
|
| 85 |
demo.launch(auth=(username, password))
|
| 86 |
+
|