DrishtiSharma commited on
Commit
879297f
·
verified ·
1 Parent(s): eccd11a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -19
app.py CHANGED
@@ -173,32 +173,48 @@ class DocumentRAG:
173
  return f"Error processing documents: {str(e)}"
174
 
175
  def generate_summary(self, text, language):
176
- """Generate a summary of the provided text focusing on specific sections in the specified language."""
177
  if not self.api_key:
178
  return "API Key not set. Please set it in the environment variables."
 
179
  try:
180
  client = OpenAI(api_key=self.api_key)
181
- response = client.chat.completions.create(
182
- model="gpt-4",
183
- messages=[
184
- {"role": "system", "content": f"""
185
- Summarize the following document focusing mainly on these sections:
186
- 1. Abstract
187
- 2. In the Introduction, specifically focus on the portion where the key contributions of the research paper are highlighted.
188
- 3. Conclusion
189
- 4. Limitations
190
- 5. Future Work
191
-
192
- Ensure the summary is concise, logically ordered, and suitable for {language}.
193
- Provide 7-9 key points for discussion in a structured format."""},
194
- {"role": "user", "content": text[:4000]}
195
- ],
196
- temperature=0.3
197
- )
198
- return response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  except Exception as e:
200
  return f"Error generating summary: {str(e)}"
201
 
 
202
  def create_podcast(self, language):
203
  """Generate a podcast script and audio based on doc summary in the specified language."""
204
  if not self.document_summary:
 
173
  return f"Error processing documents: {str(e)}"
174
 
175
  def generate_summary(self, text, language):
176
+ """Generate a structured summary from all chunks of the document."""
177
  if not self.api_key:
178
  return "API Key not set. Please set it in the environment variables."
179
+
180
  try:
181
  client = OpenAI(api_key=self.api_key)
182
+
183
+ # Split into chunks
184
+ chunks = [text[i:i + 3000] for i in range(0, len(text), 3000)]
185
+ summaries = []
186
+
187
+ for i, chunk in enumerate(chunks):
188
+ response = client.chat.completions.create(
189
+ model="gpt-4",
190
+ messages=[
191
+ {"role": "system", "content": f"""
192
+ You are a scientific summarization assistant.
193
+ Summarize the input below in {language} in a structured format, covering:
194
+ - Abstract (if present)
195
+ - Key Contributions
196
+ - Results/Findings
197
+ - Conclusion
198
+ - Limitations
199
+ - Future Work
200
+
201
+ If any section is missing, just skip it. Keep the language clear and concise.
202
+ """},
203
+ {"role": "user", "content": chunk}
204
+ ],
205
+ temperature=0.4
206
+ )
207
+
208
+ content = response.choices[0].message.content.strip()
209
+ summaries.append(f"### Part {i+1}\n{content}")
210
+
211
+ full_summary = "\n\n".join(summaries)
212
+ return full_summary
213
+
214
  except Exception as e:
215
  return f"Error generating summary: {str(e)}"
216
 
217
+
218
  def create_podcast(self, language):
219
  """Generate a podcast script and audio based on doc summary in the specified language."""
220
  if not self.document_summary: