gresci KishoreK commited on
Commit
eb328b1
0 Parent(s):

Duplicate from EuroPython2022/Translate-with-Bloom

Browse files

Co-authored-by: KishoreKunisetty <KishoreK@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +27 -0
  2. README.md +14 -0
  3. app.py +95 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.onnx filter=lfs diff=lfs merge=lfs -text
13
+ *.ot filter=lfs diff=lfs merge=lfs -text
14
+ *.parquet filter=lfs diff=lfs merge=lfs -text
15
+ *.pb filter=lfs diff=lfs merge=lfs -text
16
+ *.pt filter=lfs diff=lfs merge=lfs -text
17
+ *.pth filter=lfs diff=lfs merge=lfs -text
18
+ *.rar filter=lfs diff=lfs merge=lfs -text
19
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
21
+ *.tflite filter=lfs diff=lfs merge=lfs -text
22
+ *.tgz filter=lfs diff=lfs merge=lfs -text
23
+ *.wasm filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Translate With Bloom
3
+ emoji: 🐠
4
+ colorFrom: yellow
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.0.26
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: EuroPython2022/Translate-with-Bloom
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import gradio as gr
4
+ import requests
5
+ import os
6
+ import json #
7
+
8
+ ##Bloom
9
+ API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
10
+ # HF_TOKEN = os.environ["HF_TOKEN"]
11
+ # headers = {"Authorization": f"Bearer {HF_TOKEN}"}
12
+
13
+ def translate(prompt_ , from_lang, to_lang, input_prompt = "translate this", seed = 42):
14
+
15
+ prompt = f"Instruction : Given an {from_lang} input sentence translate it into {to_lang} sentence. \n input : \"{prompt_}\" \n {to_lang} : "
16
+ if len(prompt) == 0:
17
+ prompt = input_prompt
18
+
19
+ json_ = {
20
+ "inputs": prompt,
21
+ "parameters": {
22
+ "top_p": 0.9,
23
+ "temperature": 1.1,
24
+ "max_new_tokens": 250,
25
+ "return_full_text": False,
26
+ "do_sample": False,
27
+ "seed": seed,
28
+ "early_stopping": False,
29
+ "length_penalty": 0.0,
30
+ "eos_token_id": None,
31
+ },
32
+ "options": {
33
+ "use_cache": True,
34
+ "wait_for_model": True,
35
+ },
36
+ }
37
+ response = requests.request("POST", API_URL, json=json_) # headers=headers
38
+ # output = response.json()
39
+ output = json.loads(response.content.decode("utf-8"))
40
+ output_tmp = output[0]['generated_text']
41
+ solution = output_tmp.split(f"\n{to_lang}:")[0]
42
+
43
+
44
+ if '\n\n' in solution:
45
+ final_solution = solution.split("\n\n")[0]
46
+ else:
47
+ final_solution = solution
48
+ return final_solution
49
+
50
+ demo = gr.Blocks()
51
+
52
+ with demo:
53
+ gr.Markdown("<h1><center>Translate with Bloom</center></h1>")
54
+ gr.Markdown('''
55
+ ## Model Details
56
+ BLOOM is an autoregressive Large Language Model (LLM), trained to continue text
57
+ from a prompt on vast amounts of text data using industrial-scale computational
58
+ resources. As such, it is able to output coherent text in 46 languages and 13
59
+ programming languages that is hardly distinguishable from text written by humans.
60
+ BLOOM can also be instructed to perform text tasks it hasn't been explicitly trained
61
+ for, by casting them as text generation tasks.
62
+
63
+ ## Project Details
64
+ In this project we are going to explore the translation capabitlies of "BLOOM".
65
+
66
+ ## How to use
67
+ At the moment this space has only capacity to translate between English, Spanish and Hindi languages.
68
+ from languange is the languge you put in text box and to langauge is to what language you are intended to translate.
69
+ Select from language from the drop down.
70
+ Select to language from the drop down.
71
+
72
+ people are encouraged to improve this space by contributing.
73
+
74
+ this space is created by [Kishore](https://www.linkedin.com/in/kishore-kunisetty-925a3919a/) inorder to participate in [EuroPython22](https://huggingface.co/EuroPython2022)
75
+ please like the project to support my contribution to EuroPython22. 😊
76
+ ''')
77
+ with gr.Row():
78
+ from_lang = gr.Dropdown(['English', 'Spanish', 'Hindi'],
79
+ value='English',
80
+ label='select From language : ')
81
+ to_lang = gr.Dropdown(['English', 'Spanish', 'Hindi'],
82
+ value='Hindi',
83
+ label= 'select to Language : ')
84
+
85
+ input_prompt = gr.Textbox(label="Enter the sentence : ",
86
+ value=f"Instruction: ... \ninput: \"from sentence\" \n{to_lang} :",
87
+ lines=6)
88
+
89
+ generated_txt = gr.Textbox(lines=3)
90
+
91
+ b1 = gr.Button("translate")
92
+ b1.click(translate,inputs=[ input_prompt, from_lang, to_lang], outputs=generated_txt)
93
+
94
+ demo.launch(enable_queue=True, debug=True)
95
+