traversaal-ai commited on
Commit
d59caf9
·
1 Parent(s): 5eae515

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+ # Set your OpenAI API key here
5
+
6
+
7
+ openai.api_key = os.environ.get("openai_api_key")
8
+
9
+ # Define a function to generate responses using GPT-3.5 Turbo
10
+ def generate_response(user_prompt):
11
+
12
+ # Define the system message
13
+ system_msg = 'You are a helpful assistant.'
14
+
15
+ # Define the user message
16
+ prompt= f'''I will give you a question and you detect which category does this question belong to. It should be from these categories -
17
+ physical activity, sleep, nutrition and preventive care. Make sure you just reply with response in json format "category":"[sleep,nutrition]".
18
+ 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
19
+ Question: {user_prompt}'''
20
+ #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.'
21
+
22
+ # Create a dataset using GPT
23
+
24
+ response = openai.ChatCompletion.create(
25
+ model="gpt-3.5-turbo", # Use GPT-3.5 Turbo engine,
26
+ messages=[{"role": "system", "content": system_msg},
27
+ {"role": "user", "content": prompt}],
28
+ max_tokens=100, # You can adjust this to limit the response length
29
+ )
30
+ return response["choices"][0]["message"]["content"]
31
+
32
+ # Create a Gradio interface
33
+
34
+ iface = gr.Interface(fn=generate_response,
35
+ inputs=[gr.components.Textbox( label="prompt",
36
+ value='Who is the target population for Abdominal Aortic Aneurysm (AAA) screening?')],
37
+ outputs=[gr.JSON(label="category")]
38
+ )
39
+
40
+ # Start the Gradio interface
41
+ iface.launch()