Spaces:
Sleeping
Sleeping
gera
commited on
Commit
·
b816bdf
1
Parent(s):
a4bf226
longer display
Browse files
app.py
CHANGED
@@ -59,43 +59,44 @@ def chat(user_message, history, state):
|
|
59 |
yield total
|
60 |
|
61 |
def chat_nostream(user_message, history, state):
|
62 |
-
if state['user']
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
thread
|
68 |
-
|
69 |
-
|
70 |
-
"
|
|
|
|
|
71 |
}
|
72 |
-
|
73 |
-
|
74 |
-
state['thread'] = thread
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
|
99 |
|
100 |
def new_state():
|
101 |
return gr.State({
|
@@ -120,7 +121,7 @@ AUTH_JS = """function auth_js(token, state) {
|
|
120 |
return [token, state]
|
121 |
}
|
122 |
"""
|
123 |
-
with gr.Blocks(title="Dr. Luis Chiozza - Medicina y Psicoanalisis") as demo:
|
124 |
state = new_state()
|
125 |
gr.ChatInterface(
|
126 |
chat,
|
|
|
59 |
yield total
|
60 |
|
61 |
def chat_nostream(user_message, history, state):
|
62 |
+
if (state is None) or (not state['user']):
|
63 |
+
gr.Warning("You need to authenticate first")
|
64 |
+
yield
|
65 |
+
else:
|
66 |
+
thread = state['thread']
|
67 |
+
if thread is None:
|
68 |
+
thread = client.beta.threads.create(
|
69 |
+
tool_resources={
|
70 |
+
"file_search": {
|
71 |
+
"vector_store_ids": [vector_id]
|
72 |
+
}
|
73 |
}
|
74 |
+
)
|
75 |
+
state['thread'] = thread
|
|
|
76 |
|
77 |
+
# Add the user's message to the thread
|
78 |
+
client.beta.threads.messages.create(
|
79 |
+
thread_id=thread.id,
|
80 |
+
role="user",
|
81 |
+
content=user_message,
|
82 |
+
)
|
83 |
|
84 |
+
# Run the Assistant
|
85 |
+
run = client.beta.threads.runs.create(thread_id=thread.id,
|
86 |
+
assistant_id=assistant_id)
|
87 |
|
88 |
+
while True:
|
89 |
+
run_status = client.beta.threads.runs.retrieve(thread_id=thread.id,
|
90 |
+
run_id=run.id)
|
91 |
+
print(f"Run status: {run_status.status}")
|
92 |
+
if run_status.status == 'completed':
|
93 |
+
break
|
94 |
+
sleep(5)
|
95 |
|
96 |
+
messages = client.beta.threads.messages.list(thread_id=thread.id)
|
97 |
+
response = messages.data[0].content[0].text.value
|
98 |
|
99 |
+
yield response
|
100 |
|
101 |
def new_state():
|
102 |
return gr.State({
|
|
|
121 |
return [token, state]
|
122 |
}
|
123 |
"""
|
124 |
+
with gr.Blocks(title="Dr. Luis Chiozza - Medicina y Psicoanalisis", fill_height=True) as demo:
|
125 |
state = new_state()
|
126 |
gr.ChatInterface(
|
127 |
chat,
|