Hanxiaofeng123 commited on
Commit
8aaaea4
·
1 Parent(s): 2280d10

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +2 -8
  2. flagged/log.csv +2 -0
  3. requirements.txt +1 -0
  4. translate.py +14 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Homework2
3
- emoji: 👀
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 3.50.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Hanxiaofeng123/homework2
3
+ app_file: translate.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.50.2
 
 
6
  ---
 
 
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ text,output,flag,username,timestamp
2
+ 1,,,,2023-10-31 09:44:20.061131
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ sentencepiece
translate.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ print ("Loading translator...")
5
+
6
+ model_name = "Helsinki-NLP/opus-mt-en-zh"
7
+ # tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ translator = pipeline(task="translation_en_to_zh", model=model_name)
9
+
10
+ def translate(text):
11
+ return translator(text)[0]['translation_text']
12
+
13
+ gr.Interface(fn=translate, inputs="text", outputs="text").launch()
14
+