Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,34 @@ import openai
|
|
| 2 |
from keys import mykey
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
openai.api_key = mykey["mediQ"]
|
| 6 |
|
|
|
|
| 7 |
def gpt_response(message, history=[]):
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
response = openai.ChatCompletion.create(
|
| 10 |
model="gpt-4",
|
| 11 |
-
messages=
|
| 12 |
-
{"role": "system", "content": "You are a careful and experienced clinical reasoning expert."},
|
| 13 |
-
{"role": "user", "content": prompt}
|
| 14 |
-
],
|
| 15 |
temperature=0.3,
|
| 16 |
max_tokens=300
|
| 17 |
)
|
|
|
|
| 18 |
reply = response["choices"][0]["message"]["content"]
|
| 19 |
return reply
|
| 20 |
|
|
|
|
| 21 |
gr.ChatInterface(
|
| 22 |
fn=gpt_response,
|
| 23 |
title="🧠 MediQ GPT-4 Clinical Reasoning",
|
| 24 |
-
description="
|
| 25 |
).launch()
|
|
|
|
| 2 |
from keys import mykey
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Set your OpenAI API key
|
| 6 |
openai.api_key = mykey["mediQ"]
|
| 7 |
|
| 8 |
+
# Chat function
|
| 9 |
def gpt_response(message, history=[]):
|
| 10 |
+
# Reformat history into proper OpenAI chat message format
|
| 11 |
+
messages = [
|
| 12 |
+
{"role": "system", "content": "You are a careful and experienced clinical reasoning expert."}
|
| 13 |
+
]
|
| 14 |
+
for user_msg, bot_msg in history:
|
| 15 |
+
messages.append({"role": "user", "content": user_msg})
|
| 16 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 17 |
+
messages.append({"role": "user", "content": message})
|
| 18 |
+
|
| 19 |
+
# Call OpenAI GPT-4
|
| 20 |
response = openai.ChatCompletion.create(
|
| 21 |
model="gpt-4",
|
| 22 |
+
messages=messages,
|
|
|
|
|
|
|
|
|
|
| 23 |
temperature=0.3,
|
| 24 |
max_tokens=300
|
| 25 |
)
|
| 26 |
+
|
| 27 |
reply = response["choices"][0]["message"]["content"]
|
| 28 |
return reply
|
| 29 |
|
| 30 |
+
# Gradio chat interface
|
| 31 |
gr.ChatInterface(
|
| 32 |
fn=gpt_response,
|
| 33 |
title="🧠 MediQ GPT-4 Clinical Reasoning",
|
| 34 |
+
description="Ask a clinical question. GPT-4 will simulate adaptive expert reasoning.",
|
| 35 |
).launch()
|