reygml commited on
Commit
b6e71f1
·
1 Parent(s): be6e716
Files changed (1) hide show
  1. ui.py +8 -47
ui.py CHANGED
@@ -8,7 +8,7 @@ import streamlit as st
8
  from PIL import Image
9
 
10
  st.set_page_config(page_title="SmolVLM UI", layout="wide")
11
- st.title("SmolVLM — Streamlit + FastAPI")
12
 
13
  API_BASE = os.getenv("API_BASE", "http://127.0.0.1:8000")
14
 
@@ -36,14 +36,14 @@ def show_metrics(metrics: dict):
36
  cols[3].metric("GPU reserved (MB)", f"{vram:.0f}" if vram is not None else "—")
37
  st.expander("All metrics").json(info)
38
 
39
- tab_upload, tab_urls, tab_detect = st.tabs(["Upload images", "Image URLs", "Detect & Describe"])
40
 
41
  # -------------------- Tab 1: uploads -> /generate --------------------
42
  with tab_upload:
43
- st.subheader("Upload one or more images")
44
  files = st.file_uploader("Images", type=["png", "jpg", "jpeg", "webp"], accept_multiple_files=True)
45
- prompt = st.text_area("Prompt", "Can you describe the image(s)?", height=80)
46
- run = st.button("Generate from uploads", type="primary", use_container_width=True, key="run_files")
47
 
48
  if run:
49
  if not files or not prompt.strip():
@@ -88,48 +88,9 @@ with tab_upload:
88
  except Exception:
89
  st.write(e.response.text)
90
 
91
- # -------------------- Tab 2: URLs -> /generate_urls --------------------
92
- with tab_urls:
93
- st.subheader("Use remote image URLs")
94
- prompt2 = st.text_area("Prompt", "Can you describe the image(s)?", height=80, key="prompt_urls")
95
- urls_raw = st.text_area("One URL per line", "", height=120,
96
- placeholder="https://example.com/a.jpg\nhttps://example.com/b.png")
97
- run2 = st.button("Generate from URLs", type="primary", use_container_width=True, key="run_urls")
98
-
99
- if run2:
100
- urls = [u.strip() for u in urls_raw.splitlines() if u.strip()]
101
- if not urls or not prompt2.strip():
102
- st.error("Please add at least one URL and a prompt.")
103
- else:
104
- with st.spinner("Calling FastAPI…"):
105
- body = {
106
- "prompt": prompt2,
107
- "image_urls": urls,
108
- "max_new_tokens": max_new_tokens,
109
- "temperature": temperature, # FastAPI model allows null
110
- "top_p": top_p,
111
- }
112
- try:
113
- r = requests.post(f"{API_BASE}/generate_urls", json=body, timeout=300)
114
- r.raise_for_status()
115
- out = r.json()
116
- st.success("Done!")
117
- st.subheader("Answer")
118
- st.write(out.get("text", ""))
119
- show_metrics(out.get("metrics", {}))
120
- st.caption("Fetched URLs:")
121
- st.code(json.dumps(urls, indent=2))
122
- except requests.RequestException as e:
123
- st.error(f"Request failed: {e}")
124
- if hasattr(e, "response") and e.response is not None:
125
- try:
126
- st.code(e.response.text, language="json")
127
- except Exception:
128
- st.write(e.response.text)
129
-
130
- # -------------------- Tab 3: Detect & Describe -> /detect_describe --------------------
131
  with tab_detect:
132
- st.subheader("Grounding DINO → SmolVLM (Detect & Describe)")
133
 
134
  # Upload + labels
135
  det_image = st.file_uploader("Image", type=["jpg", "jpeg", "png", "webp"], accept_multiple_files=False)
@@ -151,7 +112,7 @@ with tab_detect:
151
  det_pad = st.slider("crop padding (fraction)", 0.0, 0.2, 0.06, 0.01)
152
  det_max_new = st.slider("max_new_tokens", 1, 512, 160, 1)
153
 
154
- run_det = st.button("Detect & Describe", type="primary", use_container_width=True)
155
  if run_det:
156
  if not det_bytes or not det_labels.strip():
157
  st.error("Please provide an image and at least one label.")
 
8
  from PIL import Image
9
 
10
  st.set_page_config(page_title="SmolVLM UI", layout="wide")
11
+ st.title("SmolVLM Grounding")
12
 
13
  API_BASE = os.getenv("API_BASE", "http://127.0.0.1:8000")
14
 
 
36
  cols[3].metric("GPU reserved (MB)", f"{vram:.0f}" if vram is not None else "—")
37
  st.expander("All metrics").json(info)
38
 
39
+ tab_upload, tab_detect = st.tabs(["SmolVLM Detection", "Grounded Detection"])
40
 
41
  # -------------------- Tab 1: uploads -> /generate --------------------
42
  with tab_upload:
43
+ st.subheader("Upload an image")
44
  files = st.file_uploader("Images", type=["png", "jpg", "jpeg", "webp"], accept_multiple_files=True)
45
+ prompt = st.text_area("Prompt", "Can you describe the image?", height=80)
46
+ run = st.button("Generate", type="primary", use_container_width=True, key="run_files")
47
 
48
  if run:
49
  if not files or not prompt.strip():
 
88
  except Exception:
89
  st.write(e.response.text)
90
 
91
+ # -------------------- Tab 2: Detect & Describe -> /detect_describe --------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  with tab_detect:
93
+ st.subheader("SmolVLM Grounded Detection")
94
 
95
  # Upload + labels
96
  det_image = st.file_uploader("Image", type=["jpg", "jpeg", "png", "webp"], accept_multiple_files=False)
 
112
  det_pad = st.slider("crop padding (fraction)", 0.0, 0.2, 0.06, 0.01)
113
  det_max_new = st.slider("max_new_tokens", 1, 512, 160, 1)
114
 
115
+ run_det = st.button("Detect", type="primary", use_container_width=True)
116
  if run_det:
117
  if not det_bytes or not det_labels.strip():
118
  st.error("Please provide an image and at least one label.")