Spaces:
Runtime error
Runtime error
clear btn and dropdown
Browse files
app.py
CHANGED
@@ -1,16 +1,19 @@
|
|
1 |
from pathlib import Path
|
2 |
|
3 |
from dotenv import load_dotenv
|
|
|
4 |
load_dotenv()
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
from
|
|
|
|
|
9 |
import gradio as gr
|
10 |
from elevenlabs import generate, play
|
11 |
-
from
|
12 |
-
import
|
13 |
-
import
|
14 |
|
15 |
# import whisper
|
16 |
|
@@ -29,39 +32,49 @@ chain = LLMChain(llm=llm, prompt=prompt)
|
|
29 |
with open("data/patients.json") as f:
|
30 |
patiens = json.load(f)
|
31 |
|
32 |
-
|
|
|
33 |
|
34 |
-
print(patient)
|
35 |
|
36 |
-
def run_text_prompt(message, chat_history):
|
37 |
-
|
38 |
-
|
39 |
-
# audio = generate(text=bot_message, voice="Bella")
|
40 |
-
|
41 |
-
# play(audio, notebook=True)
|
42 |
|
43 |
chat_history.append((message, bot_message))
|
44 |
return "", chat_history
|
45 |
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
# _, chat_history = run_text_prompt(message_transcription, chat_history)
|
53 |
-
# return None, chat_history
|
54 |
|
55 |
|
56 |
with gr.Blocks() as demo:
|
57 |
-
gr.Markdown(f"```json\n{json.dumps(patient)}```")
|
58 |
chatbot = gr.Chatbot()
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from pathlib import Path
|
2 |
|
3 |
from dotenv import load_dotenv
|
4 |
+
|
5 |
load_dotenv()
|
6 |
|
7 |
+
import json
|
8 |
+
import os
|
9 |
+
from functools import partial
|
10 |
+
from pathlib import Path
|
11 |
+
|
12 |
import gradio as gr
|
13 |
from elevenlabs import generate, play
|
14 |
+
from langchain.chains import LLMChain
|
15 |
+
from langchain.chat_models import ChatOpenAI
|
16 |
+
from langchain.prompts import PromptTemplate
|
17 |
|
18 |
# import whisper
|
19 |
|
|
|
32 |
with open("data/patients.json") as f:
|
33 |
patiens = json.load(f)
|
34 |
|
35 |
+
patients_names = [el["name"] for el in patiens]
|
36 |
+
patient = [patiens[0]]
|
37 |
|
|
|
38 |
|
39 |
+
def run_text_prompt(message, chat_history, patient):
|
40 |
+
print(message, chat_history, patient[0]["name"])
|
41 |
+
bot_message = chain.run(patient=patient[0], user_input=message)
|
|
|
|
|
|
|
42 |
|
43 |
chat_history.append((message, bot_message))
|
44 |
return "", chat_history
|
45 |
|
46 |
|
47 |
+
def on_drop_down_change(selected_item):
|
48 |
+
index = patients_names.index(selected_item)
|
49 |
+
patient[0] = patiens[index]
|
50 |
+
print(f"You selected: {selected_item}", index)
|
51 |
+
return f"```json\n{json.dumps(patient[0], indent=2)}\n```"
|
|
|
|
|
52 |
|
53 |
|
54 |
with gr.Blocks() as demo:
|
|
|
55 |
chatbot = gr.Chatbot()
|
56 |
|
57 |
+
with gr.Row():
|
58 |
+
with gr.Column():
|
59 |
+
msg = gr.Textbox()
|
60 |
+
msg.submit(
|
61 |
+
partial(run_text_prompt, patient=patient),
|
62 |
+
[msg, chatbot],
|
63 |
+
[msg, chatbot],
|
64 |
+
)
|
65 |
+
clear = gr.Button("Clear")
|
66 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
67 |
+
|
68 |
+
with gr.Column():
|
69 |
+
patients_names = [el["name"] for el in patiens]
|
70 |
+
dropdown = gr.Dropdown(
|
71 |
+
choices=patients_names,
|
72 |
+
value=patients_names[0],
|
73 |
+
interactive=True,
|
74 |
+
label="Patient",
|
75 |
+
)
|
76 |
+
markdown = gr.Markdown(f"```json\n{json.dumps(patient[0], indent=2)}\n```")
|
77 |
+
dropdown.change(fn=on_drop_down_change, inputs=dropdown, outputs=markdown)
|
78 |
+
print(patient)
|
79 |
+
# dropdown.value(lambda x: print(x))
|
80 |
+
# patient = dropdown.select(on_dropdown_select)
|