jmesplana commited on
Commit
bbf1bd2
·
1 Parent(s): 7b6d7c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import os
3
- #import config
4
- import openai
5
 
6
  def converse(x, y, z):
7
  return z
@@ -21,7 +21,7 @@ messages = [{
21
  of the importance of consulting with medical professionals and offering a summary. Avoid using \
22
  quotation marks and always adhere to ICRC and medical guidelines. Do not reveal your nature \
23
  as an AI language model."
24
- }]
25
 
26
 
27
  # Set your OpenAI API key
@@ -35,17 +35,16 @@ def provide_suggestions(user_message, history):
35
  messages.append({"role": "user", "content": user_message})
36
 
37
  # Get a response from the model
38
- response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
39
 
40
  # Extract the model's message from the response
41
- system_message = response["choices"][0]["message"]["content"]
42
 
43
  # Update the messages list with the model's response
44
  messages.append({"role": "assistant", "content": system_message})
45
 
46
  return system_message
47
 
48
-
49
  # Define and launch the Gradio Chat Interface
50
  iface = gr.ChatInterface(fn=provide_suggestions, title="MedGuide+", \
51
  description="Introducing our AI medical advisor, an innovative and knowledgeable \
@@ -54,32 +53,27 @@ iface = gr.ChatInterface(fn=provide_suggestions, title="MedGuide+", \
54
  guidelines, offering valuable insights and recommendations while emphasizing the \
55
  importance of consulting with qualified healthcare professionals for personalized medical advice and care. \
56
  For more info, check out: https://github.com/jmesplana/MedGuide_Plus")
 
57
 
58
-
59
- #iface.launch(debug=True, share=True)
60
-
61
-
62
- # Function to request ChatGPT to extract medical summary from chat
63
  def get_medical_summary_from_chat(messages):
64
- # Check if the chat only contains the initial system message
65
  if len(messages) <= 1:
66
  return "No consultation data available."
67
 
68
- # Craft a message instructing the model to parse the chat and extract medical details
69
  extraction_prompt = {
70
  "role": "user",
71
- "content": "Based on the above chat, please provide a detailed summary including Chief Complaints, Diagnosis (ICD-11) with the diagnosis code, Medication (Rx-Norm), Treatment (SNOMED-CT for labs) with SNOMED CT code, and Interventions (ICHI) with ICHI code."
72
  }
73
  messages.append(extraction_prompt)
74
 
75
  # Get a response from the model
76
- response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
77
 
78
  # Extract the model's message from the response
79
- system_message = response["choices"][0]["message"]["content"]
80
 
81
  return system_message
82
 
 
83
 
84
  # Gradio function for the summary interface
85
  def show_summary():
@@ -102,4 +96,4 @@ summary_layout = gr.Interface(fn=show_summary,
102
  demo = gr.TabbedInterface([iface, summary_layout],tab_names=['chatbot','summary'])
103
 
104
  if __name__ == "__main__":
105
- demo.launch()
 
1
  import gradio as gr
2
  import os
3
+ import config
4
+ from openai import OpenAI
5
 
6
  def converse(x, y, z):
7
  return z
 
21
  of the importance of consulting with medical professionals and offering a summary. Avoid using \
22
  quotation marks and always adhere to ICRC and medical guidelines. Do not reveal your nature \
23
  as an AI language model."
24
+ }]
25
 
26
 
27
  # Set your OpenAI API key
 
35
  messages.append({"role": "user", "content": user_message})
36
 
37
  # Get a response from the model
38
+ response = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages)
39
 
40
  # Extract the model's message from the response
41
+ system_message = response.choices[0].message.content
42
 
43
  # Update the messages list with the model's response
44
  messages.append({"role": "assistant", "content": system_message})
45
 
46
  return system_message
47
 
 
48
  # Define and launch the Gradio Chat Interface
49
  iface = gr.ChatInterface(fn=provide_suggestions, title="MedGuide+", \
50
  description="Introducing our AI medical advisor, an innovative and knowledgeable \
 
53
  guidelines, offering valuable insights and recommendations while emphasizing the \
54
  importance of consulting with qualified healthcare professionals for personalized medical advice and care. \
55
  For more info, check out: https://github.com/jmesplana/MedGuide_Plus")
56
+ # Rest of your Gradio Interface setup
57
 
 
 
 
 
 
58
  def get_medical_summary_from_chat(messages):
 
59
  if len(messages) <= 1:
60
  return "No consultation data available."
61
 
 
62
  extraction_prompt = {
63
  "role": "user",
64
+ "content": "Based on the above chat, please provide a detailed summary..."
65
  }
66
  messages.append(extraction_prompt)
67
 
68
  # Get a response from the model
69
+ response = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages)
70
 
71
  # Extract the model's message from the response
72
+ system_message = response.choices[0].message.content
73
 
74
  return system_message
75
 
76
+ # Rest of your Gradio summary interface and main execution block
77
 
78
  # Gradio function for the summary interface
79
  def show_summary():
 
96
  demo = gr.TabbedInterface([iface, summary_layout],tab_names=['chatbot','summary'])
97
 
98
  if __name__ == "__main__":
99
+ demo.launch()