File size: 1,582 Bytes
2c02f83 c976c04 2c02f83 c976c04 2c02f83 e1653e4 d54ca4f 2c02f83 e1653e4 c976c04 2c02f83 d54ca4f 2c02f83 c976c04 2c02f83 |
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 38 39 40 41 42 43 44 45 46 47 |
import openai
import gradio as gr
import os
# Set your OpenAI API key here
openai.api_key = os.environ.get("openai_api_key")
# Define a function to generate responses using GPT-3.5 Turbo
def generate_response(user_prompt):
# response = openai.ChatCompletion.create(
# engine="gpt432k", #engine = "leadership",
# messages=[
# {"role": "system", "content": "You are a helpful assistant."},
# {"role": "user", "content": prompt}
# ],
# temperature=0,
# max_tokens=200
# # stream = True
# )
# text = response['choices'][0]['message']['content']
# return text
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # Use GPT-3.5 Turbo engine
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, # You can adjust this to limit the response length
)
return response['choices'][0]['message']['content']
# Create a Gradio interface
iface = gr.Interface(
fn=generate_response,
inputs="text",
outputs="text",
title="Detect Prompt Category",
description="Enter a prompt",
)
# Start the Gradio interface
iface.launch()
|