Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
-
|
| 4 |
import os
|
| 5 |
-
import torch
|
| 6 |
|
| 7 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 8 |
|
|
@@ -10,9 +9,7 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
| 10 |
filename = "output_topic_details.txt" # Path to the file storing destress-specific details
|
| 11 |
retrieval_model_name = 'output/sentence-transformer-finetuned/'
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
| 15 |
-
model = GPT2LMHeadModel.from_pretrained("gpt2")
|
| 16 |
|
| 17 |
system_message = "You are a comfort chatbot specialized in providing information on therapy, destressing activities, and student opportunities."
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
|
@@ -75,7 +72,13 @@ def generate_response(user_query, relevant_segment):
|
|
| 75 |
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 76 |
|
| 77 |
# Append assistant's message to messages list for context
|
| 78 |
-
messages.append({"role": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
return output_text
|
| 80 |
|
| 81 |
except Exception as e:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
import openai
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 7 |
|
|
|
|
| 9 |
filename = "output_topic_details.txt" # Path to the file storing destress-specific details
|
| 10 |
retrieval_model_name = 'output/sentence-transformer-finetuned/'
|
| 11 |
|
| 12 |
+
#openai.api_key = os.environ["OPENAI_API_KEY"]
|
|
|
|
|
|
|
| 13 |
|
| 14 |
system_message = "You are a comfort chatbot specialized in providing information on therapy, destressing activities, and student opportunities."
|
| 15 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 72 |
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 73 |
|
| 74 |
# Append assistant's message to messages list for context
|
| 75 |
+
messages.append({"role": "user", "content": user_message})
|
| 76 |
+
|
| 77 |
+
response = openai.ChatCompletion.create(
|
| 78 |
+
model="gpt-4o",
|
| 79 |
+
messages=messages,
|
| 80 |
+
max_tokens=4000,
|
| 81 |
+
temperature=0.5,
|
| 82 |
return output_text
|
| 83 |
|
| 84 |
except Exception as e:
|