Spaces:
Runtime error
Runtime error
Commit
·
c976c04
1
Parent(s):
e1653e4
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
# Set your OpenAI API key here
|
| 5 |
-
api_key = "YOUR_API_KEY"
|
| 6 |
|
| 7 |
-
|
| 8 |
-
openai.api_key =
|
| 9 |
|
| 10 |
# Define a function to generate responses using GPT-3.5 Turbo
|
| 11 |
def generate_response(user_prompt):
|
|
@@ -15,7 +14,7 @@ def generate_response(user_prompt):
|
|
| 15 |
physical activity, sleep, nutrition and preventive care. Make sure you just reply with response in json format "category":"[sleep,nutrition]".
|
| 16 |
Note that single question may belong to multiple categories. Dont add any opening lines just reply with json response.
|
| 17 |
Question: {user_prompt}''',
|
| 18 |
-
max_tokens=
|
| 19 |
)
|
| 20 |
return response.choices[0].text
|
| 21 |
|
|
@@ -25,7 +24,7 @@ iface = gr.Interface(
|
|
| 25 |
inputs="text",
|
| 26 |
outputs="text",
|
| 27 |
title="Detect Prompt Category",
|
| 28 |
-
description="Enter a prompt
|
| 29 |
)
|
| 30 |
|
| 31 |
# Start the Gradio interface
|
|
|
|
| 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):
|
|
|
|
| 14 |
physical activity, sleep, nutrition and preventive care. Make sure you just reply with response in json format "category":"[sleep,nutrition]".
|
| 15 |
Note that single question may belong to multiple categories. Dont add any opening lines just reply with json response.
|
| 16 |
Question: {user_prompt}''',
|
| 17 |
+
max_tokens=100, # You can adjust this to limit the response length
|
| 18 |
)
|
| 19 |
return response.choices[0].text
|
| 20 |
|
|
|
|
| 24 |
inputs="text",
|
| 25 |
outputs="text",
|
| 26 |
title="Detect Prompt Category",
|
| 27 |
+
description="Enter a prompt",
|
| 28 |
)
|
| 29 |
|
| 30 |
# Start the Gradio interface
|