Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ import json
|
|
12 |
from rank_bm25 import BM25Okapi
|
13 |
import pandas as pd
|
14 |
import gradio as gr
|
15 |
-
|
16 |
|
17 |
# Load dataset
|
18 |
dataset_url = "https://huggingface.co/datasets/username/mental-health-classification/resolve/main/train.csv"
|
@@ -27,7 +27,8 @@ if "OPENAI_API_KEY" not in os.environ:
|
|
27 |
raise ValueError("Please set your OpenAI API key using `os.environ['OPENAI_API_KEY'] = 'your_api_key'`")
|
28 |
|
29 |
# Initialize OpenAI API
|
30 |
-
|
|
|
31 |
|
32 |
# Few-shot classification function
|
33 |
def classify_text(input_text, k=20):
|
@@ -65,7 +66,7 @@ def classify_text(input_text, k=20):
|
|
65 |
"""
|
66 |
|
67 |
try:
|
68 |
-
response =
|
69 |
messages=[
|
70 |
{"role": "system", "content": "You are a mental health specialist."},
|
71 |
{"role": "user", "content": prompt},
|
|
|
12 |
from rank_bm25 import BM25Okapi
|
13 |
import pandas as pd
|
14 |
import gradio as gr
|
15 |
+
import openai
|
16 |
|
17 |
# Load dataset
|
18 |
dataset_url = "https://huggingface.co/datasets/username/mental-health-classification/resolve/main/train.csv"
|
|
|
27 |
raise ValueError("Please set your OpenAI API key using `os.environ['OPENAI_API_KEY'] = 'your_api_key'`")
|
28 |
|
29 |
# Initialize OpenAI API
|
30 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
31 |
+
|
32 |
|
33 |
# Few-shot classification function
|
34 |
def classify_text(input_text, k=20):
|
|
|
66 |
"""
|
67 |
|
68 |
try:
|
69 |
+
response = openai.ChatCompletion.create(
|
70 |
messages=[
|
71 |
{"role": "system", "content": "You are a mental health specialist."},
|
72 |
{"role": "user", "content": prompt},
|