gera commited on
Commit
d6df1ce
·
1 Parent(s): cf9e661

Added answer length selection

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -2,13 +2,17 @@ from os import getenv as os_getenv, path as os_path
2
  from time import sleep
3
  from json import loads as json_loads
4
  import gradio as gr
5
- import openai
6
- client = openai.OpenAI()
7
 
8
  assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
9
  vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
10
 
11
- def chat(user_message, history, state):
 
 
 
 
12
  if (state is None) or (not state['user']):
13
  gr.Warning("You need to authenticate first")
14
  yield
@@ -20,7 +24,7 @@ def chat(user_message, history, state):
20
  "file_search": {
21
  "vector_store_ids": [vector_id]
22
  }
23
- }
24
  )
25
  state['thread'] = thread
26
 
@@ -30,9 +34,16 @@ def chat(user_message, history, state):
30
  content=user_message,
31
  )
32
 
 
 
 
 
 
 
33
  with client.beta.threads.runs.stream(
34
  thread_id=thread.id,
35
  assistant_id=assistant_id,
 
36
  ) as stream:
37
  total = ''
38
  for delta in stream.text_deltas:
@@ -102,13 +113,28 @@ AUTH_JS = """function auth_js(token, state) {
102
  return [token, state]
103
  }
104
  """
105
- with gr.Blocks(title="Dr. Luis Chiozza - Medicina y Psicoanalisis", fill_height=True) as demo:
 
 
106
  state = new_state()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  gr.ChatInterface(
108
  chat,
109
- title="Dr. Luis Chiozza - Medicina y Psicoanalisis",
110
- description="Habla con la colección de Medicina y Psicoanalisis del Dr. Luis Chiozza",
111
- additional_inputs=[state],
112
  examples=[
113
  ["Qué diferencias hay entre el cuerpo y el Alma?"],
114
  ["Cuáles son las distintas funciones de los órganos del cuerpo y su relación con el alma?"],
 
2
  from time import sleep
3
  from json import loads as json_loads
4
  import gradio as gr
5
+ from openai import OpenAI
6
+ client = OpenAI()
7
 
8
  assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
9
  vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
10
 
11
+ ANS_SHORT = "Resumida"
12
+ ANS_REGULAR = "Normal"
13
+ ANS_LONG = "Detallada"
14
+
15
+ def chat(user_message, history, state, long_or_short):
16
  if (state is None) or (not state['user']):
17
  gr.Warning("You need to authenticate first")
18
  yield
 
24
  "file_search": {
25
  "vector_store_ids": [vector_id]
26
  }
27
+ },
28
  )
29
  state['thread'] = thread
30
 
 
34
  content=user_message,
35
  )
36
 
37
+ details = ""
38
+ if long_or_short == ANS_SHORT:
39
+ details = "Please make a complete but short answer"
40
+ elif long_or_short == ANS_LONG:
41
+ details = "Please make complete and detailed answer. Long is better than short. Use tables and lists if you need it"
42
+
43
  with client.beta.threads.runs.stream(
44
  thread_id=thread.id,
45
  assistant_id=assistant_id,
46
+ additional_instructions=details,
47
  ) as stream:
48
  total = ''
49
  for delta in stream.text_deltas:
 
113
  return [token, state]
114
  }
115
  """
116
+
117
+
118
+ with gr.Blocks(title="Dr. Luis Chiozza - Medicina y Psicoanalisis", fill_height=True, theme=gr.themes.Base()) as demo:
119
  state = new_state()
120
+
121
+ gr.HTML("""
122
+ <h1>Dr. Luis Chiozza - Medicina y Psicoanalisis</h1>
123
+ <p>Habla con la colección de Medicina y Psicoanalisis del Dr. Luis Chiozza</p>
124
+ """)
125
+ with gr.Row(variant="compact"):
126
+ gr.HTML("Largo de la respuesta")
127
+ long_or_short = gr.Radio(
128
+ choices = [ANS_SHORT, ANS_REGULAR, ANS_LONG],
129
+ value = ANS_REGULAR,
130
+ show_label=False,
131
+ container=False,
132
+ label = "Largo de la respuesta",
133
+ scale=3)
134
+
135
  gr.ChatInterface(
136
  chat,
137
+ additional_inputs=[state, long_or_short],
 
 
138
  examples=[
139
  ["Qué diferencias hay entre el cuerpo y el Alma?"],
140
  ["Cuáles son las distintas funciones de los órganos del cuerpo y su relación con el alma?"],