Spaces:
Runtime error
Runtime error
Commit
·
455ebe4
1
Parent(s):
d54ca4f
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,30 +8,26 @@ 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 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# text = response['choices'][0]['message']['content']
|
| 24 |
|
| 25 |
-
# return text
|
| 26 |
response = openai.ChatCompletion.create(
|
| 27 |
model="gpt-3.5-turbo", # Use GPT-3.5 Turbo engine
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
Note that single question may belong to multiple categories. Dont add any opening lines just reply with json response.
|
| 31 |
-
Question: {user_prompt}''',
|
| 32 |
max_tokens=100, # You can adjust this to limit the response length
|
| 33 |
)
|
| 34 |
-
return response[
|
| 35 |
|
| 36 |
# Create a Gradio interface
|
| 37 |
iface = gr.Interface(
|
|
|
|
| 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.
|
| 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 |
iface = gr.Interface(
|