Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,6 @@ from pptx import Presentation
|
|
| 9 |
from io import StringIO
|
| 10 |
from bs4 import BeautifulSoup
|
| 11 |
import re
|
| 12 |
-
import json
|
| 13 |
import google.generativeai as genai
|
| 14 |
|
| 15 |
# Setup
|
|
@@ -73,22 +72,6 @@ def load_and_extract_text(file_path):
|
|
| 73 |
script_or_style.decompose()
|
| 74 |
return soup.get_text(separator='\n', strip=True)
|
| 75 |
|
| 76 |
-
elif ext == 'py':
|
| 77 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
| 78 |
-
return f.read()
|
| 79 |
-
|
| 80 |
-
elif ext == 'ipynb':
|
| 81 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
| 82 |
-
notebook = json.load(f)
|
| 83 |
-
cells = notebook.get("cells", [])
|
| 84 |
-
extracted = []
|
| 85 |
-
for cell in cells:
|
| 86 |
-
if cell.get("cell_type") == "markdown":
|
| 87 |
-
extracted.append("### Markdown:\n" + ''.join(cell.get("source", [])))
|
| 88 |
-
elif cell.get("cell_type") == "code":
|
| 89 |
-
extracted.append("### Code:\n" + ''.join(cell.get("source", [])))
|
| 90 |
-
return '\n'.join(extracted)
|
| 91 |
-
|
| 92 |
else:
|
| 93 |
return "Unsupported file format."
|
| 94 |
|
|
@@ -98,10 +81,7 @@ def load_and_extract_text(file_path):
|
|
| 98 |
# File uploader
|
| 99 |
uploaded_file = st.file_uploader(
|
| 100 |
"Upload a document or image",
|
| 101 |
-
type=[
|
| 102 |
-
"docx", "xlsx", "pdf", "csv", "txt", "pptx", "tex", "html", "htm",
|
| 103 |
-
"jpg", "jpeg", "png", "py", "ipynb"
|
| 104 |
-
]
|
| 105 |
)
|
| 106 |
|
| 107 |
# Question input
|
|
|
|
| 9 |
from io import StringIO
|
| 10 |
from bs4 import BeautifulSoup
|
| 11 |
import re
|
|
|
|
| 12 |
import google.generativeai as genai
|
| 13 |
|
| 14 |
# Setup
|
|
|
|
| 72 |
script_or_style.decompose()
|
| 73 |
return soup.get_text(separator='\n', strip=True)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
else:
|
| 76 |
return "Unsupported file format."
|
| 77 |
|
|
|
|
| 81 |
# File uploader
|
| 82 |
uploaded_file = st.file_uploader(
|
| 83 |
"Upload a document or image",
|
| 84 |
+
type=["docx", "xlsx", "pdf", "csv", "txt", "pptx", "tex", "html", "htm", "jpg", "jpeg", "png"]
|
|
|
|
|
|
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
# Question input
|