|
import openai |
|
import gradio as gr |
|
import os |
|
|
|
|
|
|
|
openai.api_key = os.environ.get("openai_api_key") |
|
|
|
|
|
def generate_response(user_prompt): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo", |
|
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. |
|
Question: {user_prompt}''', |
|
max_tokens=100, |
|
) |
|
return response['choices'][0]['message']['content'] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_response, |
|
inputs="text", |
|
outputs="text", |
|
title="Detect Prompt Category", |
|
description="Enter a prompt", |
|
) |
|
|
|
|
|
iface.launch() |
|
|