Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
-
# FIX 1: Metriken deaktivieren (falls noch nötig)
|
| 3 |
-
os.environ["STREAMLIT_GATHER_USAGE_STATS"] = "false"
|
| 4 |
-
# FIX 2: Streamlit Home-Verzeichnis in den beschreibbaren /tmp-Bereich umleiten
|
| 5 |
-
os.environ["STREAMLIT_HOME"] = "/tmp"
|
| 6 |
-
|
| 7 |
import streamlit as st
|
|
|
|
| 8 |
import requests
|
| 9 |
import json
|
| 10 |
from PIL import Image
|
|
@@ -13,14 +9,46 @@ import base64
|
|
| 13 |
import pandas as pd
|
| 14 |
import zipfile
|
| 15 |
import PyPDF2
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# --- Konfiguration ---
|
| 19 |
st.set_page_config(page_title="OpenRouter Free Interface", layout="wide", initial_sidebar_state="expanded")
|
| 20 |
OPENROUTER_API_BASE = "https://openrouter.ai/api/v1"
|
| 21 |
|
| 22 |
-
# [Der gesamte Rest Ihres Codes (Page Title, Session State, File Processing, API Calls etc.) bleibt unverändert.]
|
| 23 |
-
|
| 24 |
# --- Page Title ---
|
| 25 |
st.title("💸 OpenRouter Free-Tier Interface")
|
| 26 |
st.markdown("""
|
|
@@ -34,6 +62,7 @@ if "messages" not in st.session_state:
|
|
| 34 |
if "uploaded_content" not in st.session_state:
|
| 35 |
st.session_state.uploaded_content = None
|
| 36 |
|
|
|
|
| 37 |
# --- Datei-Verarbeitung ---
|
| 38 |
def encode_image(image):
|
| 39 |
buf = io.BytesIO()
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
import tempfile
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
from PIL import Image
|
|
|
|
| 9 |
import pandas as pd
|
| 10 |
import zipfile
|
| 11 |
import PyPDF2
|
| 12 |
+
|
| 13 |
+
# ----------------------------------------------------
|
| 14 |
+
# 🚨 KRITISCHE FIXES FÜR DEN PERMISSION ERROR
|
| 15 |
+
# Zwingt Streamlit, seine temporären/Konfigurationsdateien
|
| 16 |
+
# in den beschreibbaren /tmp-Bereich zu schreiben.
|
| 17 |
+
# ----------------------------------------------------
|
| 18 |
+
|
| 19 |
+
# 1. Temporären, beschreibbaren Pfad erstellen
|
| 20 |
+
TEMP_STREAMLIT_HOME = os.path.join(tempfile.gettempdir(), "st_config_workaround")
|
| 21 |
+
os.makedirs(TEMP_STREAMLIT_HOME, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
# 2. Umgebungsvariable STREAMLIT_HOME setzen
|
| 24 |
+
os.environ["STREAMLIT_HOME"] = TEMP_STREAMLIT_HOME
|
| 25 |
+
# Auch die Metriken vorsichtshalber deaktivieren
|
| 26 |
+
os.environ["STREAMLIT_GATHER_USAGE_STATS"] = "false"
|
| 27 |
+
|
| 28 |
+
# 3. Minimale config.toml erstellen, um Schreibversuche zu unterbinden
|
| 29 |
+
CONFIG_PATH = os.path.join(TEMP_STREAMLIT_HOME, "config.toml")
|
| 30 |
+
CONFIG_CONTENT = """
|
| 31 |
+
[browser]
|
| 32 |
+
gatherUsageStats = false
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
if not os.path.exists(CONFIG_PATH):
|
| 36 |
+
try:
|
| 37 |
+
with open(CONFIG_PATH, "w") as f:
|
| 38 |
+
f.write(CONFIG_CONTENT)
|
| 39 |
+
print(f"INFO: Streamlit config.toml erfolgreich nach {CONFIG_PATH} geschrieben.")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"WARNUNG: Konnte config.toml nicht schreiben: {e}")
|
| 42 |
+
|
| 43 |
+
# ----------------------------------------------------
|
| 44 |
+
# Ende der Workarounds
|
| 45 |
+
# ----------------------------------------------------
|
| 46 |
+
|
| 47 |
|
| 48 |
# --- Konfiguration ---
|
| 49 |
st.set_page_config(page_title="OpenRouter Free Interface", layout="wide", initial_sidebar_state="expanded")
|
| 50 |
OPENROUTER_API_BASE = "https://openrouter.ai/api/v1"
|
| 51 |
|
|
|
|
|
|
|
| 52 |
# --- Page Title ---
|
| 53 |
st.title("💸 OpenRouter Free-Tier Interface")
|
| 54 |
st.markdown("""
|
|
|
|
| 62 |
if "uploaded_content" not in st.session_state:
|
| 63 |
st.session_state.uploaded_content = None
|
| 64 |
|
| 65 |
+
|
| 66 |
# --- Datei-Verarbeitung ---
|
| 67 |
def encode_image(image):
|
| 68 |
buf = io.BytesIO()
|