Arafath10 commited on
Commit
c0f4592
·
1 Parent(s): 2e1ba7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -32
app.py CHANGED
@@ -46,47 +46,50 @@ sys = "You are a general family physician. Your mission is to figure out the dia
46
  end_sys_prompts = "\n\ngive correct treatment and most related diagnosis with ICD code don't ask any questions. if question is not related to provided data don't give answer from this provided data's"
47
 
48
 
49
- # Initialize Gradio interface
50
  with gr.Blocks() as demo:
51
  chatbot = gr.Chatbot()
52
-
53
- # Replace the text input with audio input
54
  audio_input = gr.Audio(label="Voice Input")
55
-
56
- response_text = gr.Textbox(label="Response")
57
-
58
  clear = gr.Button("Clear.")
59
  def clear_textbox():
60
- global chain, id
61
- chain = ""
62
  id = 0
63
  clear.click(clear_textbox)
64
 
65
- def respond(audio, response_text):
66
- global chain, id
67
- if audio is not None:
68
- recognizer = sr.Recognizer()
69
- try:
70
- audio_text = recognizer.recognize_google(audio)
71
- message = audio_text
72
- except sr.UnknownValueError:
73
- message = "Sorry, I couldn't understand the audio input."
74
-
75
- if id < len(medical_questionnaire):
76
- if id == 0:
77
- chain = chain + sys + "\n\n" + message + "\n\n" + medical_questionnaire[id] + "\n"
78
- response_text = message + "\n\n" + medical_questionnaire[id]
79
- id = id + 1
80
  else:
81
- chain = chain + message + "\n\n" + medical_questionnaire[id] + "\n"
82
- response_text = message + "\n\n" + medical_questionnaire[id]
83
- id = id + 1
 
 
 
84
  else:
85
- chain = chain + message + end_sys_prompts
86
- diagnosis_and_treatment = "Treatment and diagnosis information"
87
  diagnosis_and_treatment = str(diagnosis_and_treatment)
88
- chain = chain + "\n\ntreatment & diagnosis with ICD code below\n" + diagnosis_and_treatment
89
- response_text = diagnosis_and_treatment
90
 
91
- # Combine audio input and chatbot
92
- gr.Interface([audio_input, chatbot], respond, outputs=response_text, live=True, live_post=True).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  end_sys_prompts = "\n\ngive correct treatment and most related diagnosis with ICD code don't ask any questions. if question is not related to provided data don't give answer from this provided data's"
47
 
48
 
 
49
  with gr.Blocks() as demo:
50
  chatbot = gr.Chatbot()
51
+ msg = gr.Textbox(label="User Input:")
 
52
  audio_input = gr.Audio(label="Voice Input")
 
 
 
53
  clear = gr.Button("Clear.")
54
  def clear_textbox():
55
+ global chain,id
56
+ chain = ""
57
  id = 0
58
  clear.click(clear_textbox)
59
 
60
+
61
+ def respond(audio,message, chat_history):
62
+ global chain,id
63
+ if id<len(medical_questionnaire):
64
+ if id==0:
65
+ chain = chain + sys +"\n\n"+message+"\n\n"+medical_questionnaire[id]+"\n"
66
+ chat_history.append((message,medical_questionnaire[id]))
67
+ id=id+1
68
+ return "", chat_history
 
 
 
 
 
 
69
  else:
70
+
71
+ chain = chain + message+"\n\n"+medical_questionnaire[id]+"\n"
72
+ chat_history.append((message, medical_questionnaire[id]))
73
+ id=id+1
74
+ return "", chat_history
75
+
76
  else:
77
+ chain = chain+message+end_sys_prompts
78
+ diagnosis_and_treatment = "tretment"
79
  diagnosis_and_treatment = str(diagnosis_and_treatment)
 
 
80
 
81
+ chain = chain+"\n\ntreatment & diagnosis with ICD code below\n"+diagnosis_and_treatment
82
+ print(chain)
83
+ print(id)
84
+
85
+ report = "report"
86
+ report = str(report)
87
+ chat_history.append((message,report.replace("\n","<br>")))
88
+
89
+ return "", chat_history
90
+
91
+ msg.submit(respond, [audio_input,msg, chatbot], [audio_input,msg, chatbot])
92
+
93
+
94
+
95
+ demo.launch()