Update app.py
Browse files
app.py
CHANGED
|
@@ -109,8 +109,8 @@ class DocumentRAG:
|
|
| 109 |
except Exception as e:
|
| 110 |
return f"Error processing documents: {str(e)}"
|
| 111 |
|
| 112 |
-
def generate_summary(self, text):
|
| 113 |
-
"""Generate a summary of the provided text."""
|
| 114 |
if not self.api_key:
|
| 115 |
return "API Key not set. Please set it in the environment variables."
|
| 116 |
try:
|
|
@@ -118,7 +118,7 @@ class DocumentRAG:
|
|
| 118 |
response = client.chat.completions.create(
|
| 119 |
model="gpt-4",
|
| 120 |
messages=[
|
| 121 |
-
{"role": "system", "content": "Summarize the document content concisely
|
| 122 |
{"role": "user", "content": text[:4000]}
|
| 123 |
],
|
| 124 |
temperature=0.3
|
|
@@ -127,8 +127,8 @@ class DocumentRAG:
|
|
| 127 |
except Exception as e:
|
| 128 |
return f"Error generating summary: {str(e)}"
|
| 129 |
|
| 130 |
-
def create_podcast(self):
|
| 131 |
-
"""Generate a podcast script and audio based on the
|
| 132 |
if not self.document_summary:
|
| 133 |
return "Please process documents before generating a podcast.", None
|
| 134 |
|
|
@@ -142,7 +142,7 @@ class DocumentRAG:
|
|
| 142 |
script_response = client.chat.completions.create(
|
| 143 |
model="gpt-4",
|
| 144 |
messages=[
|
| 145 |
-
{"role": "system", "content": "You are a professional podcast producer. Create a natural dialogue based on the provided document summary."},
|
| 146 |
{"role": "user", "content": f"""Based on the following document summary, create a 1-2 minute podcast script:
|
| 147 |
1. Clearly label the dialogue as 'Host 1:' and 'Host 2:'
|
| 148 |
2. Keep the content engaging and insightful.
|
|
@@ -201,31 +201,13 @@ class DocumentRAG:
|
|
| 201 |
except Exception as e:
|
| 202 |
return f"Error generating podcast: {str(e)}", None
|
| 203 |
|
| 204 |
-
def
|
| 205 |
-
"""
|
| 206 |
-
if not self.api_key:
|
| 207 |
-
return "API Key not set. Please set it in the environment variables."
|
| 208 |
-
try:
|
| 209 |
-
client = OpenAI(api_key=self.api_key)
|
| 210 |
-
response = client.chat.completions.create(
|
| 211 |
-
model="gpt-4",
|
| 212 |
-
messages=[
|
| 213 |
-
{"role": "system", "content": "Summarize the document content concisely and provide 3-5 key points for discussion."},
|
| 214 |
-
{"role": "user", "content": text[:4000]}
|
| 215 |
-
],
|
| 216 |
-
temperature=0.3
|
| 217 |
-
)
|
| 218 |
-
return response.choices[0].message.content
|
| 219 |
-
except Exception as e:
|
| 220 |
-
return f"Error generating summary: {str(e)}"
|
| 221 |
-
|
| 222 |
-
def handle_query(self, question, history):
|
| 223 |
-
"""Handle user queries."""
|
| 224 |
if not self.qa_chain:
|
| 225 |
return history + [("System", "Please process the documents first.")]
|
| 226 |
try:
|
| 227 |
preface = """
|
| 228 |
-
Instruction: Respond in
|
| 229 |
If you cannot provide an answer, say: "I am not sure about this question. Please try asking something else."
|
| 230 |
"""
|
| 231 |
query = f"{preface}\nQuery: {question}"
|
|
|
|
| 109 |
except Exception as e:
|
| 110 |
return f"Error processing documents: {str(e)}"
|
| 111 |
|
| 112 |
+
def generate_summary(self, text, language):
|
| 113 |
+
"""Generate a summary of the provided text in the specified language."""
|
| 114 |
if not self.api_key:
|
| 115 |
return "API Key not set. Please set it in the environment variables."
|
| 116 |
try:
|
|
|
|
| 118 |
response = client.chat.completions.create(
|
| 119 |
model="gpt-4",
|
| 120 |
messages=[
|
| 121 |
+
{"role": "system", "content": f"Summarize the document content concisely in {language}. Provide 3-5 key points for discussion."},
|
| 122 |
{"role": "user", "content": text[:4000]}
|
| 123 |
],
|
| 124 |
temperature=0.3
|
|
|
|
| 127 |
except Exception as e:
|
| 128 |
return f"Error generating summary: {str(e)}"
|
| 129 |
|
| 130 |
+
def create_podcast(self, language):
|
| 131 |
+
"""Generate a podcast script and audio based on doc summary in the specified language."""
|
| 132 |
if not self.document_summary:
|
| 133 |
return "Please process documents before generating a podcast.", None
|
| 134 |
|
|
|
|
| 142 |
script_response = client.chat.completions.create(
|
| 143 |
model="gpt-4",
|
| 144 |
messages=[
|
| 145 |
+
{"role": "system", "content": f"You are a professional podcast producer. Create a natural dialogue in {language} based on the provided document summary."},
|
| 146 |
{"role": "user", "content": f"""Based on the following document summary, create a 1-2 minute podcast script:
|
| 147 |
1. Clearly label the dialogue as 'Host 1:' and 'Host 2:'
|
| 148 |
2. Keep the content engaging and insightful.
|
|
|
|
| 201 |
except Exception as e:
|
| 202 |
return f"Error generating podcast: {str(e)}", None
|
| 203 |
|
| 204 |
+
def handle_query(self, question, history, language):
|
| 205 |
+
"""Handle user queries in the specified language."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
if not self.qa_chain:
|
| 207 |
return history + [("System", "Please process the documents first.")]
|
| 208 |
try:
|
| 209 |
preface = """
|
| 210 |
+
Instruction: Respond in {language}. Be professional and concise, keeping the response under 300 words.
|
| 211 |
If you cannot provide an answer, say: "I am not sure about this question. Please try asking something else."
|
| 212 |
"""
|
| 213 |
query = f"{preface}\nQuery: {question}"
|