gera commited on
Commit
b816bdf
·
1 Parent(s): a4bf226

longer display

Browse files
Files changed (1) hide show
  1. app.py +33 -32
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'] is None:
63
- return
64
-
65
- thread = state['thread']
66
- if thread is None:
67
- thread = client.beta.threads.create(
68
- tool_resources={
69
- "file_search": {
70
- "vector_store_ids": [vector_id]
 
 
71
  }
72
- }
73
- )
74
- state['thread'] = thread
75
 
76
- # Add the user's message to the thread
77
- client.beta.threads.messages.create(
78
- thread_id=thread.id,
79
- role="user",
80
- content=user_message,
81
- )
82
 
83
- # Run the Assistant
84
- run = client.beta.threads.runs.create(thread_id=thread.id,
85
- assistant_id=assistant_id)
86
 
87
- while True:
88
- run_status = client.beta.threads.runs.retrieve(thread_id=thread.id,
89
- run_id=run.id)
90
- print(f"Run status: {run_status.status}")
91
- if run_status.status == 'completed':
92
- break
93
- sleep(5)
94
 
95
- messages = client.beta.threads.messages.list(thread_id=thread.id)
96
- response = messages.data[0].content[0].text.value
97
 
98
- yield response
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,