Alibrown commited on
Commit
865f1d8
·
verified ·
1 Parent(s): ec6763f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -27
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
- newline = "\n"
55
- content = f"ZIP Contents:{newline}"
56
-
57
- # Whitelist für Textdateien erweitern
58
- text_extensions = ('.txt', '.csv', '.py', '.html', '.js', '.css', '.php', '.json', '.xml')
59
-
60
- for file_info in z.infolist():
61
- if not file_info.is_dir():
62
- try:
63
- with z.open(file_info.filename) as file:
64
- # Check 1: Erlaubte Dateiendung
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
- # Check 2: Ist es trotzdem Text? (Magische Bytes prüfen)
69
- else:
70
- raw_content = file.read()
71
- try:
72
- decoded_content = raw_content.decode('utf-8')
73
- content += f"{newline}📄 {file_info.filename} (unbekannte Erweiterung):{newline}{decoded_content}{newline}"
74
- except UnicodeDecodeError:
75
- content += f"{newline}⚠️ Binärdatei ignoriert: {file_info.filename}{newline}"
76
- except Exception as e:
77
- content += f"{newline}❌ Fehler bei {file_info.filename}: {str(e)}{newline}"
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")