Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +30 -12
src/streamlit_app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
import os
|
| 2 |
import json
|
| 3 |
from typing import Dict, Any, List
|
|
|
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
from transformers import (
|
|
@@ -96,24 +97,41 @@ def get_pipeline(task: str, model_id: str):
|
|
| 96 |
def section_header(title, emoji="β¨"):
|
| 97 |
st.markdown(f"## {emoji} {title}")
|
| 98 |
|
| 99 |
-
def model_picker(task_filter: str) -> Dict[str, Any]:
|
| 100 |
-
"""Model selection widget"""
|
| 101 |
subset = {k: v for k, v in MODEL_REGISTRY.items() if v["task"] == task_filter}
|
| 102 |
names = list(subset.keys())
|
| 103 |
|
|
|
|
|
|
|
|
|
|
| 104 |
if not names:
|
| 105 |
st.warning(f"No models registered for task: {task_filter}")
|
| 106 |
st.info("You can add a custom model repo ID below.")
|
| 107 |
-
repo = st.text_input(
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
choice = st.selectbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
cfg = subset[choice]
|
| 112 |
repo = st.text_input(
|
| 113 |
"Model repo on Hugging Face",
|
| 114 |
value=cfg["repo"],
|
| 115 |
placeholder="org/model-id",
|
| 116 |
-
key=f"repo_{
|
| 117 |
)
|
| 118 |
st.caption(f"**Paper**: {cfg['paper']} \n**Notes**: {cfg['notes']}")
|
| 119 |
return {
|
|
@@ -152,7 +170,7 @@ tabs = st.tabs([
|
|
| 152 |
# -----------------------------
|
| 153 |
with tabs[0]:
|
| 154 |
section_header("Meter classification (text)", "π")
|
| 155 |
-
cfg = model_picker("text-classification")
|
| 156 |
verse = st.text_area(
|
| 157 |
"Paste a single bayt (verse) or hemistich",
|
| 158 |
height=120,
|
|
@@ -202,10 +220,10 @@ with tabs[1]:
|
|
| 202 |
col1, col2 = st.columns(2)
|
| 203 |
with col1:
|
| 204 |
st.markdown("**Era**")
|
| 205 |
-
cfg_era = model_picker("text-classification")
|
| 206 |
with col2:
|
| 207 |
st.markdown("**Theme**")
|
| 208 |
-
cfg_theme = model_picker("text-classification")
|
| 209 |
|
| 210 |
text = st.text_area(
|
| 211 |
"Paste verse(s) for classification",
|
|
@@ -278,7 +296,7 @@ with tabs[1]:
|
|
| 278 |
# -----------------------------
|
| 279 |
with tabs[2]:
|
| 280 |
section_header("Diacritization (seq2seq)", "ποΈ")
|
| 281 |
-
cfg_diac = model_picker("text2text-generation")
|
| 282 |
src = st.text_area(
|
| 283 |
"Undiacritized verse(s)",
|
| 284 |
height=150,
|
|
@@ -316,7 +334,7 @@ with tabs[2]:
|
|
| 316 |
# -----------------------------
|
| 317 |
with tabs[3]:
|
| 318 |
section_header("Poetry generation", "π")
|
| 319 |
-
cfg_gen = model_picker("text-generation")
|
| 320 |
prompt = st.text_area(
|
| 321 |
"Prompt (include hints: meter / qafiyah / theme)",
|
| 322 |
height=150,
|
|
|
|
| 1 |
+
# import os
|
| 2 |
import json
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
+
import uuid
|
| 5 |
|
| 6 |
import streamlit as st
|
| 7 |
from transformers import (
|
|
|
|
| 97 |
def section_header(title, emoji="β¨"):
|
| 98 |
st.markdown(f"## {emoji} {title}")
|
| 99 |
|
| 100 |
+
def model_picker(task_filter: str, context: str = "") -> Dict[str, Any]:
|
| 101 |
+
"""Model selection widget with unique keys"""
|
| 102 |
subset = {k: v for k, v in MODEL_REGISTRY.items() if v["task"] == task_filter}
|
| 103 |
names = list(subset.keys())
|
| 104 |
|
| 105 |
+
# Create unique key suffix
|
| 106 |
+
unique_suffix = f"{context}_{task_filter}_{uuid.uuid4().hex[:8]}"
|
| 107 |
+
|
| 108 |
if not names:
|
| 109 |
st.warning(f"No models registered for task: {task_filter}")
|
| 110 |
st.info("You can add a custom model repo ID below.")
|
| 111 |
+
repo = st.text_input(
|
| 112 |
+
"Model repo on Hugging Face",
|
| 113 |
+
placeholder="org/model-id",
|
| 114 |
+
key=f"repo_custom_{unique_suffix}"
|
| 115 |
+
)
|
| 116 |
+
return {
|
| 117 |
+
"name": "Custom",
|
| 118 |
+
"task": task_filter,
|
| 119 |
+
"repo": repo,
|
| 120 |
+
"paper": "N/A",
|
| 121 |
+
"notes": "Custom model"
|
| 122 |
+
}
|
| 123 |
|
| 124 |
+
choice = st.selectbox(
|
| 125 |
+
"Pick a model",
|
| 126 |
+
names,
|
| 127 |
+
key=f"picker_{unique_suffix}"
|
| 128 |
+
)
|
| 129 |
cfg = subset[choice]
|
| 130 |
repo = st.text_input(
|
| 131 |
"Model repo on Hugging Face",
|
| 132 |
value=cfg["repo"],
|
| 133 |
placeholder="org/model-id",
|
| 134 |
+
key=f"repo_{unique_suffix}"
|
| 135 |
)
|
| 136 |
st.caption(f"**Paper**: {cfg['paper']} \n**Notes**: {cfg['notes']}")
|
| 137 |
return {
|
|
|
|
| 170 |
# -----------------------------
|
| 171 |
with tabs[0]:
|
| 172 |
section_header("Meter classification (text)", "π")
|
| 173 |
+
cfg = model_picker("text-classification", context="meter")
|
| 174 |
verse = st.text_area(
|
| 175 |
"Paste a single bayt (verse) or hemistich",
|
| 176 |
height=120,
|
|
|
|
| 220 |
col1, col2 = st.columns(2)
|
| 221 |
with col1:
|
| 222 |
st.markdown("**Era**")
|
| 223 |
+
cfg_era = model_picker("text-classification", context="era")
|
| 224 |
with col2:
|
| 225 |
st.markdown("**Theme**")
|
| 226 |
+
cfg_theme = model_picker("text-classification", context="theme")
|
| 227 |
|
| 228 |
text = st.text_area(
|
| 229 |
"Paste verse(s) for classification",
|
|
|
|
| 296 |
# -----------------------------
|
| 297 |
with tabs[2]:
|
| 298 |
section_header("Diacritization (seq2seq)", "ποΈ")
|
| 299 |
+
cfg_diac = model_picker("text2text-generation", context="diac")
|
| 300 |
src = st.text_area(
|
| 301 |
"Undiacritized verse(s)",
|
| 302 |
height=150,
|
|
|
|
| 334 |
# -----------------------------
|
| 335 |
with tabs[3]:
|
| 336 |
section_header("Poetry generation", "π")
|
| 337 |
+
cfg_gen = model_picker("text-generation", context="gen")
|
| 338 |
prompt = st.text_area(
|
| 339 |
"Prompt (include hints: meter / qafiyah / theme)",
|
| 340 |
height=150,
|