ahed9x commited on
Commit
53fca17
1 Parent(s): 07cadbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -1,12 +1,28 @@
1
- !pip install transformers
2
-
3
  import gradio as gr
4
- from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- pipe = pipeline("text2text-generation", model="mohamedtolba/franco-arabics")
 
 
 
 
 
 
 
7
 
8
- def translate(text):
9
- return pipe(text)
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