robzchhangte commited on
Commit
31dcf39
1 Parent(s): 08324af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+ from huggingface_hub import login
4
+
5
+
6
+ # Load the translation model and tokenizer from Hugging Face
7
+ model_name = "robzchhangte/enmz-helsinki-case"
8
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+
11
+ # Translation function with max_length=512
12
+ def translate(text):
13
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
14
+ outputs = model.generate(inputs["input_ids"], max_length=512) # Set max_length to 512
15
+ translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return translated_text
17
+
18
+ # Gradio Interface
19
+ interface = gr.Interface(
20
+ fn=translate,
21
+ inputs="text",
22
+ outputs="text",
23
+ title="Text Translator",
24
+ description="Translate text using the gravix321/model1 translation model.",
25
+ examples=[["Hello, how are you?"], ["What time is it?"]]
26
+ )
27
+
28
+ # Launch the Gradio app locally
29
+ interface.launch(share=False) # Set sharer=True to share your app