Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,7 +57,9 @@ class DocumentRAG:
|
|
| 57 |
documents = []
|
| 58 |
for uploaded_file in uploaded_files:
|
| 59 |
# Save uploaded file to a temporary location
|
| 60 |
-
temp_file_path = tempfile.NamedTemporaryFile(
|
|
|
|
|
|
|
| 61 |
with open(temp_file_path, "wb") as temp_file:
|
| 62 |
temp_file.write(uploaded_file.read())
|
| 63 |
|
|
@@ -91,7 +93,6 @@ class DocumentRAG:
|
|
| 91 |
# Combine text for later summary generation
|
| 92 |
self.document_text = " ".join([doc.page_content for doc in documents]) # Store for later use
|
| 93 |
|
| 94 |
-
|
| 95 |
# Create embeddings and initialize retrieval chain
|
| 96 |
embeddings = OpenAIEmbeddings(api_key=self.api_key)
|
| 97 |
self.document_store = Chroma.from_documents(
|
|
@@ -112,7 +113,6 @@ class DocumentRAG:
|
|
| 112 |
except Exception as e:
|
| 113 |
return f"Error processing documents: {str(e)}"
|
| 114 |
|
| 115 |
-
|
| 116 |
def generate_summary(self, text, language):
|
| 117 |
"""Generate a summary of the provided text focusing on specific sections in the specified language."""
|
| 118 |
if not self.api_key:
|
|
@@ -123,21 +123,20 @@ class DocumentRAG:
|
|
| 123 |
model="gpt-4",
|
| 124 |
messages=[
|
| 125 |
{"role": "system", "content": f"""
|
| 126 |
-
Summarize the following document focusing mainly
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
},
|
| 136 |
{"role": "user", "content": text[:4000]}
|
| 137 |
],
|
| 138 |
temperature=0.3
|
| 139 |
-
|
| 140 |
-
|
| 141 |
except Exception as e:
|
| 142 |
return f"Error generating summary: {str(e)}"
|
| 143 |
|
|
|
|
| 57 |
documents = []
|
| 58 |
for uploaded_file in uploaded_files:
|
| 59 |
# Save uploaded file to a temporary location
|
| 60 |
+
temp_file_path = tempfile.NamedTemporaryFile(
|
| 61 |
+
delete=False, suffix=os.path.splitext(uploaded_file.name)[1]
|
| 62 |
+
).name
|
| 63 |
with open(temp_file_path, "wb") as temp_file:
|
| 64 |
temp_file.write(uploaded_file.read())
|
| 65 |
|
|
|
|
| 93 |
# Combine text for later summary generation
|
| 94 |
self.document_text = " ".join([doc.page_content for doc in documents]) # Store for later use
|
| 95 |
|
|
|
|
| 96 |
# Create embeddings and initialize retrieval chain
|
| 97 |
embeddings = OpenAIEmbeddings(api_key=self.api_key)
|
| 98 |
self.document_store = Chroma.from_documents(
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
return f"Error processing documents: {str(e)}"
|
| 115 |
|
|
|
|
| 116 |
def generate_summary(self, text, language):
|
| 117 |
"""Generate a summary of the provided text focusing on specific sections in the specified language."""
|
| 118 |
if not self.api_key:
|
|
|
|
| 123 |
model="gpt-4",
|
| 124 |
messages=[
|
| 125 |
{"role": "system", "content": f"""
|
| 126 |
+
Summarize the following document focusing mainly on these sections:
|
| 127 |
+
1. Abstract
|
| 128 |
+
2. In the Introduction, specifically focus on the portion where the key contributions of the research paper are highlighted.
|
| 129 |
+
3. Conclusion
|
| 130 |
+
4. Limitations
|
| 131 |
+
5. Future Work
|
| 132 |
+
|
| 133 |
+
Ensure the summary is concise, logically ordered, and suitable for {language}.
|
| 134 |
+
Provide 5-7 key points for discussion in a structured format."""},
|
|
|
|
| 135 |
{"role": "user", "content": text[:4000]}
|
| 136 |
],
|
| 137 |
temperature=0.3
|
| 138 |
+
)
|
| 139 |
+
return response.choices[0].message.content
|
| 140 |
except Exception as e:
|
| 141 |
return f"Error generating summary: {str(e)}"
|
| 142 |
|