Update app.py
Browse files
app.py
CHANGED
@@ -50,35 +50,35 @@ def process_file(uploaded_file):
|
|
50 |
return {"type": "text", "content": "".join(page.extract_text() for page in reader.pages if page.extract_text())}
|
51 |
|
52 |
if file_type == "zip":
|
53 |
-
with zipfile.ZipFile(uploaded_file) as z:
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
return {"type": "text", "content": content}
|
80 |
|
81 |
return {"type": "error", "content": "Unsupported file format"}
|
|
|
82 |
# Sidebar für Einstellungen
|
83 |
with st.sidebar:
|
84 |
api_key = st.text_input("Google AI API Key", type="password")
|
|
|
50 |
return {"type": "text", "content": "".join(page.extract_text() for page in reader.pages if page.extract_text())}
|
51 |
|
52 |
if file_type == "zip":
|
53 |
+
with zipfile.ZipFile(uploaded_file) as z: # <- Hier beginnt der Block
|
54 |
+
newline = "\n"
|
55 |
+
content = f"ZIP Contents:{newline}"
|
56 |
+
|
57 |
+
text_extensions = ('.txt', '.csv', '.py', '.html', '.js', '.css',
|
58 |
+
'.php', '.json', '.xml', '.c', '.cpp', '.java',
|
59 |
+
'.cs', '.rb', '.go', '.ts', '.swift', '.kt', '.rs', '.sh', '.sql')
|
60 |
+
|
61 |
+
for file_info in z.infolist():
|
62 |
+
if not file_info.is_dir():
|
63 |
+
try:
|
64 |
+
with z.open(file_info.filename) as file:
|
65 |
+
if file_info.filename.lower().endswith(text_extensions):
|
66 |
+
file_content = file.read().decode('utf-8')
|
67 |
+
content += f"{newline}📄 {file_info.filename}:{newline}{file_content}{newline}"
|
68 |
+
else:
|
69 |
+
raw_content = file.read()
|
70 |
+
try:
|
71 |
+
decoded_content = raw_content.decode('utf-8')
|
72 |
+
content += f"{newline}📄 {file_info.filename} (unbekannte Erweiterung):{newline}{decoded_content}{newline}"
|
73 |
+
except UnicodeDecodeError:
|
74 |
+
content += f"{newline}⚠️ Binärdatei ignoriert: {file_info.filename}{newline}"
|
75 |
+
except Exception as e:
|
76 |
+
content += f"{newline}❌ Fehler bei {file_info.filename}: {str(e)}{newline}"
|
77 |
+
|
78 |
+
return {"type": "text", "content": content} # Korrekt eingerückt
|
|
|
79 |
|
80 |
return {"type": "error", "content": "Unsupported file format"}
|
81 |
+
|
82 |
# Sidebar für Einstellungen
|
83 |
with st.sidebar:
|
84 |
api_key = st.text_input("Google AI API Key", type="password")
|