wagner-austin
commited on
Commit
·
460624d
1
Parent(s):
3fee86b
Initial Space: Gradio launcher + deps
Browse files- .gitignore +4 -0
- app.py +58 -0
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.env/
|
| 4 |
+
temp.txt
|
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Very small launcher for the Space.
|
| 3 |
+
|
| 4 |
+
If you followed the earlier guide and added src/ui/gradio_app.py
|
| 5 |
+
inside your package, just import its `launch()` helper.
|
| 6 |
+
|
| 7 |
+
Otherwise (or while you’re still developing) uncomment the
|
| 8 |
+
‘quick-and-dirty’ block at the bottom; it builds a trivial UI
|
| 9 |
+
inline and will work as long as the core library is on PyPI.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
# ---------- Preferred: use the packaged UI ----------
|
| 13 |
+
try:
|
| 14 |
+
from uci_phonotactic_calculator.ui.gradio_app import launch
|
| 15 |
+
except ImportError:
|
| 16 |
+
launch = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# ------------------------------------------------------------------
|
| 20 |
+
# Fallback: tiny self-contained demo (remove when real UI is shipped)
|
| 21 |
+
# ------------------------------------------------------------------
|
| 22 |
+
if launch is None:
|
| 23 |
+
import tempfile, os, pandas as pd, gradio as gr
|
| 24 |
+
from uci_phonotactic_calculator.ngram_calculator import run
|
| 25 |
+
from uci_phonotactic_calculator.plugins import PluginRegistry
|
| 26 |
+
|
| 27 |
+
def score(train_csv, test_csv,
|
| 28 |
+
model, run_all, ngram_order):
|
| 29 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 30 |
+
out_file = os.path.join(tmp, "scores.csv")
|
| 31 |
+
run(train_csv.name,
|
| 32 |
+
test_csv.name,
|
| 33 |
+
out_file,
|
| 34 |
+
model=None if run_all else model,
|
| 35 |
+
run_all=run_all,
|
| 36 |
+
filters=None,
|
| 37 |
+
show_progress=False,
|
| 38 |
+
extra_args=None)
|
| 39 |
+
return pd.read_csv(out_file)
|
| 40 |
+
|
| 41 |
+
launch = lambda: gr.Interface(
|
| 42 |
+
fn=score,
|
| 43 |
+
inputs=[
|
| 44 |
+
gr.File(label="Training CSV"),
|
| 45 |
+
gr.File(label="Test CSV"),
|
| 46 |
+
gr.Dropdown(choices=sorted(PluginRegistry),
|
| 47 |
+
label="Model", value="ngram"),
|
| 48 |
+
gr.Checkbox(label="Run full variant grid", value=False),
|
| 49 |
+
gr.Slider(1, 4, step=1, value=2, label="N-gram order")
|
| 50 |
+
],
|
| 51 |
+
outputs=gr.Dataframe(label="Scores"),
|
| 52 |
+
title="UCI Phonotactic Calculator",
|
| 53 |
+
description="Upload training & test corpora, choose a model, and get probability scores."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# ---------- Launch ----------
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uci-phonotactic-calculator[ui]==0.2.0 # latest published wheel
|