Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,14 +14,15 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
14 |
|
15 |
def detect_language(text):
|
16 |
"""Detects the language of the input text using OpenAI."""
|
17 |
-
|
|
|
18 |
model="gpt-3.5-turbo",
|
19 |
messages=[
|
20 |
{"role": "system", "content": "Detect the language of this text."},
|
21 |
{"role": "user", "content": text}
|
22 |
]
|
23 |
)
|
24 |
-
return response
|
25 |
|
26 |
# Set up OpenAI API key (replace with your key)
|
27 |
openai.api_key = "YOUR_OPENAI_API_KEY"
|
@@ -109,14 +110,15 @@ def combine_text_from_files(extracted_files):
|
|
109 |
|
110 |
def generate_response(question, text):
|
111 |
"""Uses OpenAI to answer a question based on extracted text."""
|
112 |
-
|
|
|
113 |
model="gpt-3.5-turbo",
|
114 |
messages=[
|
115 |
{"role": "system", "content": "You are a data analytics assistant. Answer the question based on the provided document content."},
|
116 |
{"role": "user", "content": f"{question}\n\nBased on the following document content:\n{text[:3000]}"} # Limit to 3000 characters to avoid excessive token usage
|
117 |
]
|
118 |
)
|
119 |
-
return response
|
120 |
|
121 |
def chatbot_interface(question):
|
122 |
folder_path = "New_Data_Analytics/"
|
|
|
14 |
|
15 |
def detect_language(text):
|
16 |
"""Detects the language of the input text using OpenAI."""
|
17 |
+
client = openai.OpenAI()
|
18 |
+
response = client.chat.completions.create(
|
19 |
model="gpt-3.5-turbo",
|
20 |
messages=[
|
21 |
{"role": "system", "content": "Detect the language of this text."},
|
22 |
{"role": "user", "content": text}
|
23 |
]
|
24 |
)
|
25 |
+
return response.choices[0].message.content.strip()
|
26 |
|
27 |
# Set up OpenAI API key (replace with your key)
|
28 |
openai.api_key = "YOUR_OPENAI_API_KEY"
|
|
|
110 |
|
111 |
def generate_response(question, text):
|
112 |
"""Uses OpenAI to answer a question based on extracted text."""
|
113 |
+
client = openai.OpenAI()
|
114 |
+
response = client.chat.completions.create(
|
115 |
model="gpt-3.5-turbo",
|
116 |
messages=[
|
117 |
{"role": "system", "content": "You are a data analytics assistant. Answer the question based on the provided document content."},
|
118 |
{"role": "user", "content": f"{question}\n\nBased on the following document content:\n{text[:3000]}"} # Limit to 3000 characters to avoid excessive token usage
|
119 |
]
|
120 |
)
|
121 |
+
return response.choices[0].message.content.strip()
|
122 |
|
123 |
def chatbot_interface(question):
|
124 |
folder_path = "New_Data_Analytics/"
|