Spaces:
Runtime error
Runtime error
submit function
Browse files
app.py
CHANGED
@@ -73,23 +73,11 @@ class AASLDConversationalAgent():
|
|
73 |
|
74 |
AASLD_CONVERSATIONAL_AGENT = AASLDConversationalAgent()
|
75 |
|
76 |
-
PAGE_TITLE = """
|
77 |
-
# Arithmedics AASLD Guidelines Assistant
|
78 |
-
#### I'm a chatbot using gpt-4 model from OpenAI.
|
79 |
-
### I help practictioners quickly get answers from AASLD Practice Guidelines
|
80 |
-
"""
|
81 |
-
|
82 |
PAGE_TITLE_HTML = """
|
83 |
<h1> Arithmedics - AASLD Guidelines Assistant</h1>
|
84 |
-
<h4> I'm a chatbot using gpt-4 model from OpenAI. </h4>
|
85 |
<h3> I help practictioners quickly get answers from AASLD Practice Guidelines </h3>
|
86 |
"""
|
87 |
|
88 |
-
DEFAULT_ROLE = """
|
89 |
-
You are a chat assistant who helps medical practictioners get quick answers from
|
90 |
-
the practice guidelines published by "The American Association for the Study of
|
91 |
-
Liver Diseases (AASLD)." If you cannot find the answer please let the user know.
|
92 |
-
"""
|
93 |
def get_empty_state():
|
94 |
return {'total_tokens': 0, 'messages': []}
|
95 |
|
@@ -97,9 +85,27 @@ def clear_conversation():
|
|
97 |
return (gr.update(value=None, visible=True), None, '', get_empty_state(),
|
98 |
'', '')
|
99 |
|
100 |
-
def submit_question(question):
|
101 |
print(question)
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
css = """
|
105 |
#col-container {max-width: 80%; margin-left: auto; margin-right: auto;}
|
@@ -115,8 +121,6 @@ with gr.Blocks(css=css, title='AASLD Practice Guidelines ') as demo:
|
|
115 |
state = gr.State(get_empty_state())
|
116 |
with gr.Column(elem_id='col-container'):
|
117 |
gr.Image('Arithmedics_rectangle_logo.png', elem_id='arithmedics-img')
|
118 |
-
# gr.Markdown(PAGE_TITLE,
|
119 |
-
# elem_id='header')
|
120 |
gr.HTML(PAGE_TITLE_HTML, elem_id='header')
|
121 |
with gr.Row():
|
122 |
with gr.Column(scale=7):
|
|
|
73 |
|
74 |
AASLD_CONVERSATIONAL_AGENT = AASLDConversationalAgent()
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
PAGE_TITLE_HTML = """
|
77 |
<h1> Arithmedics - AASLD Guidelines Assistant</h1>
|
|
|
78 |
<h3> I help practictioners quickly get answers from AASLD Practice Guidelines </h3>
|
79 |
"""
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
def get_empty_state():
|
82 |
return {'total_tokens': 0, 'messages': []}
|
83 |
|
|
|
85 |
return (gr.update(value=None, visible=True), None, '', get_empty_state(),
|
86 |
'', '')
|
87 |
|
88 |
+
def submit_question(question, messages):
|
89 |
print(question)
|
90 |
+
history = messages
|
91 |
+
prompt_msg = { 'role': 'user', 'content': question }
|
92 |
+
history.append(prompt_msg)
|
93 |
+
try:
|
94 |
+
answer = AASLD_CONVERSATIONAL_AGENT.get_answer(question)
|
95 |
+
print(answer)
|
96 |
+
answer_msg = { 'role': 'AI', 'content': answer }
|
97 |
+
history.append(answer_msg)
|
98 |
+
except Exception as e:
|
99 |
+
print(e)
|
100 |
+
history.append({
|
101 |
+
'role': 'system',
|
102 |
+
'content': f'Error: {e}'
|
103 |
+
})
|
104 |
+
chat_messages = [
|
105 |
+
(history[i]['content'], history[i+1]['content'])
|
106 |
+
for i in range(0, len(history)-1, 2)]
|
107 |
+
chat_messages.reverse()
|
108 |
+
return ('', chat_messages, '', {'total_tokens': 0, 'messages': []}, question, answer)
|
109 |
|
110 |
css = """
|
111 |
#col-container {max-width: 80%; margin-left: auto; margin-right: auto;}
|
|
|
121 |
state = gr.State(get_empty_state())
|
122 |
with gr.Column(elem_id='col-container'):
|
123 |
gr.Image('Arithmedics_rectangle_logo.png', elem_id='arithmedics-img')
|
|
|
|
|
124 |
gr.HTML(PAGE_TITLE_HTML, elem_id='header')
|
125 |
with gr.Row():
|
126 |
with gr.Column(scale=7):
|