Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,7 +92,6 @@ def fetch_model_contexts(api_key):
|
|
| 92 |
contexts[mid] = ctx
|
| 93 |
return contexts
|
| 94 |
except Exception as e:
|
| 95 |
-
# Hier kein st.warning, da es den Cache ungültig machen könnte, wenn API-Key noch nicht da ist
|
| 96 |
return {}
|
| 97 |
|
| 98 |
|
|
@@ -118,7 +117,6 @@ with st.sidebar:
|
|
| 118 |
default_ctx = model_contexts.get(model, 4096)
|
| 119 |
|
| 120 |
temperature = st.slider("Temperature", 0.0, 1.0, 0.7)
|
| 121 |
-
# Slider Maxwert auf Context-Länge des Modells setzen, Min-Output-Tokens auf 512
|
| 122 |
max_tokens = st.slider(
|
| 123 |
f"Max Output Tokens (max {default_ctx})",
|
| 124 |
1,
|
|
@@ -142,15 +140,15 @@ with st.sidebar:
|
|
| 142 |
""")
|
| 143 |
|
| 144 |
|
| 145 |
-
# --- Datei Upload ---
|
| 146 |
uploaded_file = st.file_uploader("Upload File (optional)",
|
| 147 |
type=["jpg", "jpeg", "png", "txt", "pdf", "zip", "csv", "xlsx", "html", "css", "js", "py"])
|
| 148 |
|
|
|
|
| 149 |
if uploaded_file and st.session_state.uploaded_content is None:
|
| 150 |
st.session_state.uploaded_content = process_file(uploaded_file)
|
| 151 |
-
#
|
| 152 |
-
|
| 153 |
-
|
| 154 |
|
| 155 |
if st.session_state.uploaded_content:
|
| 156 |
processed = st.session_state.uploaded_content
|
|
@@ -165,7 +163,7 @@ if st.session_state.uploaded_content:
|
|
| 165 |
# Anhang einzeln entfernen
|
| 166 |
if st.button("❌ Remove Attachment"):
|
| 167 |
st.session_state.uploaded_content = None
|
| 168 |
-
st.experimental_rerun()
|
| 169 |
|
| 170 |
|
| 171 |
# --- Chat Verlauf anzeigen ---
|
|
@@ -174,7 +172,7 @@ for msg in st.session_state.messages:
|
|
| 174 |
st.markdown(msg["content"])
|
| 175 |
|
| 176 |
|
| 177 |
-
# --- API Call ---
|
| 178 |
def call_openrouter(model, messages, temp, max_tok, key):
|
| 179 |
headers = {
|
| 180 |
"Authorization": f"Bearer {key}",
|
|
|
|
| 92 |
contexts[mid] = ctx
|
| 93 |
return contexts
|
| 94 |
except Exception as e:
|
|
|
|
| 95 |
return {}
|
| 96 |
|
| 97 |
|
|
|
|
| 117 |
default_ctx = model_contexts.get(model, 4096)
|
| 118 |
|
| 119 |
temperature = st.slider("Temperature", 0.0, 1.0, 0.7)
|
|
|
|
| 120 |
max_tokens = st.slider(
|
| 121 |
f"Max Output Tokens (max {default_ctx})",
|
| 122 |
1,
|
|
|
|
| 140 |
""")
|
| 141 |
|
| 142 |
|
| 143 |
+
# --- Datei Upload & Preview Logik ---
|
| 144 |
uploaded_file = st.file_uploader("Upload File (optional)",
|
| 145 |
type=["jpg", "jpeg", "png", "txt", "pdf", "zip", "csv", "xlsx", "html", "css", "js", "py"])
|
| 146 |
|
| 147 |
+
# NEUE/KORRIGIERTE LOGIK: Nur verarbeiten, wenn eine neue Datei hochgeladen wird und KEIN Inhalt im State ist
|
| 148 |
if uploaded_file and st.session_state.uploaded_content is None:
|
| 149 |
st.session_state.uploaded_content = process_file(uploaded_file)
|
| 150 |
+
# KEIN st.experimental_rerun() hier! Streamlit rendert die Vorschau beim nächsten regulären Durchlauf.
|
| 151 |
+
# Siehe Gemini Code: Dort fehlt dieser Rerun auch.
|
|
|
|
| 152 |
|
| 153 |
if st.session_state.uploaded_content:
|
| 154 |
processed = st.session_state.uploaded_content
|
|
|
|
| 163 |
# Anhang einzeln entfernen
|
| 164 |
if st.button("❌ Remove Attachment"):
|
| 165 |
st.session_state.uploaded_content = None
|
| 166 |
+
st.experimental_rerun() # Hier ist der Rerun notwendig, um den uploader zu leeren
|
| 167 |
|
| 168 |
|
| 169 |
# --- Chat Verlauf anzeigen ---
|
|
|
|
| 172 |
st.markdown(msg["content"])
|
| 173 |
|
| 174 |
|
| 175 |
+
# --- API Call Funktion ---
|
| 176 |
def call_openrouter(model, messages, temp, max_tok, key):
|
| 177 |
headers = {
|
| 178 |
"Authorization": f"Bearer {key}",
|