Spaces:
Configuration error
Configuration error
EcoFriendlyWoodVerneer commited on
Commit ·
95487ef
1
Parent(s): 6f8f3be
Placeholder Frontend while model is training
Browse files- app.py +35 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
MODEL_DIR = Path("t5_enzh")
|
| 7 |
+
def model_ready():
|
| 8 |
+
if not MODEL_DIR.exists():
|
| 9 |
+
return False
|
| 10 |
+
# accept either a final save or checkpoints
|
| 11 |
+
has_ckpt = any(p.is_dir() and p.name.startswith("checkpoint-") for p in MODEL_DIR.iterdir())
|
| 12 |
+
has_model = (MODEL_DIR / "config.json").exists() or (MODEL_DIR / "pytorch_model.bin").exists()
|
| 13 |
+
return has_ckpt or has_model
|
| 14 |
+
|
| 15 |
+
def translate_text(text: str):
|
| 16 |
+
text = (text or "").strip()
|
| 17 |
+
if not text:
|
| 18 |
+
return ""
|
| 19 |
+
if not model_ready():
|
| 20 |
+
return "[Model not ready yet — training/upload not finished. Try again later.]"
|
| 21 |
+
# TODO: load model + tokenizer here once you upload them
|
| 22 |
+
return "[Model ready — inference not wired yet]"
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("# EN → ZH Translator")
|
| 26 |
+
status = "✅ Model ready" if model_ready() else "⏳ Model not ready"
|
| 27 |
+
gr.Markdown(f"**Status:** {status}")
|
| 28 |
+
|
| 29 |
+
inp = gr.Textbox(label="English", lines=4, placeholder="Type English here...")
|
| 30 |
+
out = gr.Textbox(label="Chinese", lines=4)
|
| 31 |
+
btn = gr.Button("Translate")
|
| 32 |
+
|
| 33 |
+
btn.click(translate_text, inp, out)
|
| 34 |
+
|
| 35 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
+
transformers==4.44.2
|
| 3 |
+
torch
|
| 4 |
+
sentencepiece
|
| 5 |
+
accelerate==0.33.0
|