seawolf2357 commited on
Commit
5906ade
1 Parent(s): a0ed680

initial commit

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -1,16 +1,31 @@
1
- import gradio
2
-
3
- import numpy as np
4
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- def sepia(input_img):
7
- sepia_filter = np.array([
8
- [0.393, 0.769, 0.189],
9
- [0.349, 0.686, 0.168],
10
- [0.272, 0.534, 0.131]
11
- ])
12
- sepia_img = input_img.dot(sepia_filter.T)
13
- sepia_img /= sepia_img.max()
14
- return sepia_img
15
 
16
- gradio.Interface(sepia, gr.Image(shape=(200, 200)), "image").launch(share=True)
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
+ import torch
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ko-en")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-ko-en")
7
+
8
+ device = 0 if torch.cuda.is_available() else -1
9
+
10
+ def translate(text, src_lang, tgt_lang):
11
+ """
12
+ Translate the text from source lang to target lang
13
+ """
14
+ translation_pipeline = pipeline("translation", model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length=400, device=device)
15
+ result = translation_pipeline(text)
16
+ return result[0]['translation_text']
17
+
18
+ demo = gr.Interface(
19
+ fn=translate,
20
+ inputs=[
21
+ gr.components.Textbox(label="Text"),
22
 
23
+ ],
24
+ outputs=["text"],
25
+ examples=[["Building a translation demo with Gradio is so easy!", "eng_Latn", "spa_Latn"]],
26
+ cache_examples=False,
27
+ title="Translation Demo",
28
+ description="This demo is a simplified version of the original [NLLB-Translator](https://huggingface.co/spaces/Narrativaai/NLLB-Translator) space"
29
+ )
 
 
30
 
31
+ demo.launch()