-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArogyasathi app.py
37 lines (28 loc) · 1.19 KB
/
Arogyasathi app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import openai
import gradio
openai.api_key = "" #TypeYourAPIKEY
# Initial system message
messages = [{"role": "system", "content": "You are a Doctor Who gives Possible Treatment with medicine based on symptoms also suggest precautions"}]
def CustomChatGPT(user_input):
# Append user input to the messages
messages.append({"role": "user", "content": user_input})
# Call OpenAI API for Chat Completion
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
# Extract assistant's reply
assistant_reply = response["choices"][0]["message"]["content"]
# Append assistant's reply to the messages
messages.append({"role": "assistant", "content": assistant_reply})
# Gradio expects only the assistant's reply as the output
return assistant_reply
# Define the Gradio Interface
demo = gradio.Interface(
fn=CustomChatGPT,
inputs=[gradio.Textbox(type="text", placeholder="Type a message...", label="User Input")],
outputs=[gradio.Textbox(type="text", label="DoctorBot's Reply")],
title="Health Assitant by Haka",
)
# Launch the Gradio Interface
demo.launch(share=True)