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