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): # Define the system message system_msg = 'You are a helpful assistant.' # Define the user message 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}''' #user_msg = 'Create a small dataset about total sales over the last year. The format of the dataset should be a data frame with 12 rows and 2 columns. The columns should be called "month" and "total_sales_usd". The "month" column should contain the shortened forms of month names from "Jan" to "Dec". The "total_sales_usd" column should contain random numeric values taken from a normal distribution with mean 100000 and standard deviation 5000. Provide Python code to generate the dataset, then provide the output in the format of a markdown table.' # Create a dataset using GPT response = openai.ChatCompletion.create( model="gpt-3.5-turbo", # Use GPT-3.5 Turbo engine, messages=[{"role": "system", "content": system_msg}, {"role": "user", "content": 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=[gr.components.Textbox( label="prompt", value='Who is the target population for Abdominal Aortic Aneurysm (AAA) screening?')], outputs=[gr.JSON(label="category")] ) # Start the Gradio interface iface.launch()