Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
# app.py — Streamlit Frontend for Diag Studio AI
|
| 2 |
-
import os
|
|
|
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
# ---- container-safe defaults to avoid '/.streamlit' permission errors
|
|
@@ -15,8 +17,6 @@ try:
|
|
| 15 |
st._config.set_option("theme.secondaryBackgroundColor", "#171a1f")
|
| 16 |
st._config.set_option("theme.textColor", "#e6e8ea")
|
| 17 |
except Exception:
|
| 18 |
-
# Themes usually set via config.toml, but programmatic options apply at runtime.
|
| 19 |
-
# See Streamlit theming docs. # docs: https://docs.streamlit.io/develop/concepts/configuration/theming
|
| 20 |
pass
|
| 21 |
|
| 22 |
# ================= Env & API =================
|
|
@@ -115,7 +115,7 @@ backend_default = API_BASE or "http://127.0.0.1:7860"
|
|
| 115 |
api_base = st.text_input(t["backend_url"], value=backend_default)
|
| 116 |
|
| 117 |
# Health check
|
| 118 |
-
health_col,
|
| 119 |
with health_col:
|
| 120 |
if st.button("🔄 Health"):
|
| 121 |
try:
|
|
@@ -131,8 +131,45 @@ st.markdown("---")
|
|
| 131 |
|
| 132 |
# Upload or URL input
|
| 133 |
st.write(t["upload_hint"])
|
| 134 |
-
file = st.file_uploader(t["upload"], type=["mp3", "wav", "ogg"])
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
elif _audio_url.strip():
|
| 137 |
data["audio_url"] = _audio_url.strip()
|
| 138 |
|
|
@@ -169,7 +206,7 @@ if res:
|
|
| 169 |
parsed = res.get("fal_parsed")
|
| 170 |
if parsed:
|
| 171 |
st.markdown(f"**{t['json']}**")
|
| 172 |
-
st.json(parsed)
|
| 173 |
|
| 174 |
# Backend artifacts — download via Streamlit
|
| 175 |
st.markdown(f"**{t['backend_artifacts']}**")
|
|
@@ -177,7 +214,10 @@ if res:
|
|
| 177 |
col_a, col_b, col_c = st.columns(3)
|
| 178 |
|
| 179 |
def fetch_bytes(url: str) -> bytes:
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
r.raise_for_status()
|
| 182 |
return r.content
|
| 183 |
|
|
@@ -186,15 +226,17 @@ if res:
|
|
| 186 |
try:
|
| 187 |
data = fetch_bytes(dls["summary_txt"])
|
| 188 |
col_a.download_button(label=t["download_summary"], data=data, file_name="summary.txt")
|
| 189 |
-
except Exception
|
| 190 |
col_a.error("summary.txt ✖")
|
| 191 |
|
| 192 |
# parsed
|
| 193 |
if dls.get("fal_parsed_json"):
|
| 194 |
try:
|
| 195 |
data = fetch_bytes(dls["fal_parsed_json"])
|
| 196 |
-
col_b.download_button(
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
col_b.error("parsed.json ✖")
|
| 199 |
|
| 200 |
# raw
|
|
@@ -202,7 +244,7 @@ if res:
|
|
| 202 |
try:
|
| 203 |
data = fetch_bytes(dls["fal_raw_txt"])
|
| 204 |
col_c.download_button(label=t["download_raw"], data=data, file_name="raw.txt")
|
| 205 |
-
except Exception
|
| 206 |
col_c.error("raw.txt ✖")
|
| 207 |
|
| 208 |
# ===== Footer =====
|
|
|
|
| 1 |
# app.py — Streamlit Frontend for Diag Studio AI
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import requests
|
| 5 |
import streamlit as st
|
| 6 |
|
| 7 |
# ---- container-safe defaults to avoid '/.streamlit' permission errors
|
|
|
|
| 17 |
st._config.set_option("theme.secondaryBackgroundColor", "#171a1f")
|
| 18 |
st._config.set_option("theme.textColor", "#e6e8ea")
|
| 19 |
except Exception:
|
|
|
|
|
|
|
| 20 |
pass
|
| 21 |
|
| 22 |
# ================= Env & API =================
|
|
|
|
| 115 |
api_base = st.text_input(t["backend_url"], value=backend_default)
|
| 116 |
|
| 117 |
# Health check
|
| 118 |
+
health_col, _ = st.columns([0.28, 0.72])
|
| 119 |
with health_col:
|
| 120 |
if st.button("🔄 Health"):
|
| 121 |
try:
|
|
|
|
| 131 |
|
| 132 |
# Upload or URL input
|
| 133 |
st.write(t["upload_hint"])
|
| 134 |
+
file = st.file_uploader(t["upload"], type=["mp3", "wav", "ogg"])
|
| 135 |
+
st.write(f"**{t['or']}**")
|
| 136 |
+
audio_url = st.text_input(t["paste_url"], value="", placeholder="https://...")
|
| 137 |
+
|
| 138 |
+
with st.expander(t["adv"], expanded=False):
|
| 139 |
+
detailed = st.checkbox(t["detailed"], value=True)
|
| 140 |
+
use_data_uri = st.checkbox(t["use_data_uri"], value=True)
|
| 141 |
+
openai_model = st.text_input(t["model"], value="gpt-4o")
|
| 142 |
+
prompt_override = st.text_area(
|
| 143 |
+
t["prompt"],
|
| 144 |
+
value="",
|
| 145 |
+
height=140,
|
| 146 |
+
placeholder="Leave empty to use backend default prompt",
|
| 147 |
+
)
|
| 148 |
+
st.caption(t["footer"])
|
| 149 |
+
|
| 150 |
+
c1, c2 = st.columns([0.25, 0.75])
|
| 151 |
+
go = c1.button(f"▶ {t['analyze']}", type="primary")
|
| 152 |
+
reset = c2.button(f"↩ {t['reset']}")
|
| 153 |
+
|
| 154 |
+
if reset:
|
| 155 |
+
st.session_state.last_response = None
|
| 156 |
+
st.rerun()
|
| 157 |
+
|
| 158 |
+
# ============== Submission ==============
|
| 159 |
+
def post_analyze(_api_base: str, _headers: dict, _file, _audio_url: str) -> dict:
|
| 160 |
+
url = f"{_api_base}/analyze"
|
| 161 |
+
data = {
|
| 162 |
+
"detailed_analysis": "true" if detailed else "false",
|
| 163 |
+
"use_data_uri": "true" if use_data_uri else "false",
|
| 164 |
+
"openai_model": openai_model or "gpt-4o",
|
| 165 |
+
}
|
| 166 |
+
if prompt_override.strip():
|
| 167 |
+
data["prompt"] = prompt_override.strip()
|
| 168 |
+
|
| 169 |
+
files = None
|
| 170 |
+
if _file is not None:
|
| 171 |
+
mime = getattr(_file, "type", None) or "application/octet-stream"
|
| 172 |
+
files = {"file": (_file.name, _file, mime)}
|
| 173 |
elif _audio_url.strip():
|
| 174 |
data["audio_url"] = _audio_url.strip()
|
| 175 |
|
|
|
|
| 206 |
parsed = res.get("fal_parsed")
|
| 207 |
if parsed:
|
| 208 |
st.markdown(f"**{t['json']}**")
|
| 209 |
+
st.json(parsed)
|
| 210 |
|
| 211 |
# Backend artifacts — download via Streamlit
|
| 212 |
st.markdown(f"**{t['backend_artifacts']}**")
|
|
|
|
| 214 |
col_a, col_b, col_c = st.columns(3)
|
| 215 |
|
| 216 |
def fetch_bytes(url: str) -> bytes:
|
| 217 |
+
if not url:
|
| 218 |
+
raise RuntimeError("empty url")
|
| 219 |
+
full = url if url.startswith("http") else f"{api_base}{url}"
|
| 220 |
+
r = requests.get(full, headers=HEADERS, timeout=60)
|
| 221 |
r.raise_for_status()
|
| 222 |
return r.content
|
| 223 |
|
|
|
|
| 226 |
try:
|
| 227 |
data = fetch_bytes(dls["summary_txt"])
|
| 228 |
col_a.download_button(label=t["download_summary"], data=data, file_name="summary.txt")
|
| 229 |
+
except Exception:
|
| 230 |
col_a.error("summary.txt ✖")
|
| 231 |
|
| 232 |
# parsed
|
| 233 |
if dls.get("fal_parsed_json"):
|
| 234 |
try:
|
| 235 |
data = fetch_bytes(dls["fal_parsed_json"])
|
| 236 |
+
col_b.download_button(
|
| 237 |
+
label=t["download_parsed"], data=data, file_name="parsed.json", mime="application/json"
|
| 238 |
+
)
|
| 239 |
+
except Exception:
|
| 240 |
col_b.error("parsed.json ✖")
|
| 241 |
|
| 242 |
# raw
|
|
|
|
| 244 |
try:
|
| 245 |
data = fetch_bytes(dls["fal_raw_txt"])
|
| 246 |
col_c.download_button(label=t["download_raw"], data=data, file_name="raw.txt")
|
| 247 |
+
except Exception:
|
| 248 |
col_c.error("raw.txt ✖")
|
| 249 |
|
| 250 |
# ===== Footer =====
|