|
import openai |
|
import gradio as gr |
|
|
|
|
|
api_key = "YOUR_API_KEY" |
|
|
|
|
|
openai.api_key = api_key |
|
|
|
|
|
def generate_response(user_prompt): |
|
response = openai.Completion.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=50, |
|
) |
|
return response.choices[0].text |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_response, |
|
inputs="text", |
|
outputs="text", |
|
title="Detect Prompt Category", |
|
description="Enter a prompt, and GPT-3.5 Turbo will generate a response.", |
|
) |
|
|
|
|
|
iface.launch() |
|
|