Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,28 @@
|
|
1 |
-
!pip install transformers
|
2 |
-
|
3 |
import gradio as gr
|
4 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
demo = gr.Interface(fn=translate, inputs="text", outputs="text")
|
12 |
-
demo.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Load the tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("mohamedtolba/franco-arabics")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("mohamedtolba/franco-arabics")
|
7 |
+
|
8 |
+
def translate_text(text):
|
9 |
+
# Tokenize the input text
|
10 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
11 |
+
# Generate the output text
|
12 |
+
outputs = model.generate(**inputs)
|
13 |
+
# Decode the generated text
|
14 |
+
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
return translated_text
|
16 |
|
17 |
+
# Create the Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=translate_text,
|
20 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Franco-Arabic text here..."),
|
21 |
+
outputs="text",
|
22 |
+
title="Franco-Arabic to Arabic Translator",
|
23 |
+
description="Translate Franco-Arabic text to Arabic using the mohamedtolba/franco-arabics model."
|
24 |
+
)
|
25 |
|
26 |
+
if __name__ == "__main__":
|
27 |
+
iface.launch()
|
28 |
|
|
|
|