Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ MODEL_MAP = {
|
|
| 13 |
"Angika to English": "snjev310/aya-101-angika-english"
|
| 14 |
}
|
| 15 |
|
|
|
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID)
|
| 17 |
|
| 18 |
@spaces.GPU(duration=180)
|
|
@@ -34,7 +35,7 @@ def translate(text, model_choice):
|
|
| 34 |
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 35 |
model.eval()
|
| 36 |
|
| 37 |
-
# Prepare Input
|
| 38 |
prompt = f"translate {model_choice}: {text}"
|
| 39 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 40 |
|
|
@@ -49,7 +50,7 @@ def translate(text, model_choice):
|
|
| 49 |
|
| 50 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 51 |
|
| 52 |
-
# Cleanup
|
| 53 |
del model
|
| 54 |
del base_model
|
| 55 |
torch.cuda.empty_cache()
|
|
@@ -57,9 +58,10 @@ def translate(text, model_choice):
|
|
| 57 |
return result
|
| 58 |
|
| 59 |
# --- Gradio UI ---
|
| 60 |
-
|
|
|
|
| 61 |
gr.Markdown("# 🗣️ Angika Machine Translation")
|
| 62 |
-
gr.Markdown("Select your translation direction below. This uses
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
|
@@ -74,7 +76,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 74 |
with gr.Column():
|
| 75 |
output_text = gr.Textbox(label="Translated Text", lines=5, interactive=False)
|
| 76 |
|
| 77 |
-
submit_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
gr.Examples(
|
| 80 |
examples=[
|
|
@@ -88,15 +94,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 88 |
with gr.Row():
|
| 89 |
with gr.Column():
|
| 90 |
gr.Markdown("### 🛠️ Help us improve!")
|
| 91 |
-
gr.Markdown("
|
| 92 |
feedback_btn = gr.Button("Submit Correct Translation", variant="secondary")
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
with gr.Column():
|
| 96 |
gr.Markdown("### ⚡ Support our computation")
|
| 97 |
-
gr.Markdown("Your support helps us
|
| 98 |
support_btn = gr.Button("Support Computation Costs ☕", variant="primary")
|
| 99 |
-
#
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
| 13 |
"Angika to English": "snjev310/aya-101-angika-english"
|
| 14 |
}
|
| 15 |
|
| 16 |
+
# Load Tokenizer globally
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID)
|
| 18 |
|
| 19 |
@spaces.GPU(duration=180)
|
|
|
|
| 35 |
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 36 |
model.eval()
|
| 37 |
|
| 38 |
+
# Prepare Input
|
| 39 |
prompt = f"translate {model_choice}: {text}"
|
| 40 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 41 |
|
|
|
|
| 50 |
|
| 51 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 52 |
|
| 53 |
+
# Cleanup for ZeroGPU
|
| 54 |
del model
|
| 55 |
del base_model
|
| 56 |
torch.cuda.empty_cache()
|
|
|
|
| 58 |
return result
|
| 59 |
|
| 60 |
# --- Gradio UI ---
|
| 61 |
+
# Theme removed from Blocks constructor for Gradio 6.0
|
| 62 |
+
with gr.Blocks() as demo:
|
| 63 |
gr.Markdown("# 🗣️ Angika Machine Translation")
|
| 64 |
+
gr.Markdown("Select your translation direction below. This uses the Aya-101 13B model.")
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column():
|
|
|
|
| 76 |
with gr.Column():
|
| 77 |
output_text = gr.Textbox(label="Translated Text", lines=5, interactive=False)
|
| 78 |
|
| 79 |
+
submit_btn.click(
|
| 80 |
+
fn=translate,
|
| 81 |
+
inputs=[input_text, model_dropdown],
|
| 82 |
+
outputs=output_text
|
| 83 |
+
)
|
| 84 |
|
| 85 |
gr.Examples(
|
| 86 |
examples=[
|
|
|
|
| 94 |
with gr.Row():
|
| 95 |
with gr.Column():
|
| 96 |
gr.Markdown("### 🛠️ Help us improve!")
|
| 97 |
+
gr.Markdown("If the translation isn't perfect, please share the correct version with us.")
|
| 98 |
feedback_btn = gr.Button("Submit Correct Translation", variant="secondary")
|
| 99 |
+
# Changed '_js' to 'js' for Gradio 6.0 compatibility
|
| 100 |
+
feedback_btn.click(
|
| 101 |
+
fn=None,
|
| 102 |
+
js='() => { window.open("https://forms.gle/FXspX7DxXHh5En6c7", "_blank"); }'
|
| 103 |
+
)
|
| 104 |
|
| 105 |
with gr.Column():
|
| 106 |
gr.Markdown("### ⚡ Support our computation")
|
| 107 |
+
gr.Markdown("Your support helps us cover the hosting costs for this 13B model.")
|
| 108 |
support_btn = gr.Button("Support Computation Costs ☕", variant="primary")
|
| 109 |
+
# Replace the link below with your Razorpay/Ko-fi link
|
| 110 |
+
support_btn.click(
|
| 111 |
+
fn=None,
|
| 112 |
+
js='() => { window.open("https://ko-fi.com/YOUR_USERNAME", "_blank"); }'
|
| 113 |
+
)
|
| 114 |
|
| 115 |
+
# Theme added to launch method for Gradio 6.0
|
| 116 |
+
demo.launch(theme=gr.themes.Soft())
|