|
import openai |
|
import gradio as gr |
|
import os |
|
|
|
|
|
|
|
openai.api_key = os.environ.get("openai_api_key") |
|
|
|
|
|
def generate_response(user_prompt): |
|
|
|
|
|
system_msg = 'You are a helpful assistant.' |
|
|
|
|
|
prompt= f'''I will give you a question and you detect which category does this question belong to. It should be from these categories - |
|
physical activity, sleep, nutrition and preventive care. Make sure you just reply with response in json format "category":"[sleep,nutrition]". |
|
Note that single question may belong to multiple categories. Dont add any opening lines just reply with json response. If there is no match return no category |
|
Question: {user_prompt}''' |
|
|
|
|
|
|
|
|
|
response = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo", |
|
messages=[{"role": "system", "content": system_msg}, |
|
{"role": "user", "content": prompt}], |
|
max_tokens=100, |
|
) |
|
return response["choices"][0]["message"]["content"] |
|
|
|
|
|
|
|
iface = gr.Interface(fn=generate_response, |
|
inputs=[gr.components.Textbox( label="prompt", |
|
value='Who is the target population for Abdominal Aortic Aneurysm (AAA) screening?')], |
|
outputs=[gr.JSON(label="category")] |
|
) |
|
|
|
|
|
iface.launch() |
|
|