Spaces:
Running
Running
toaster61
commited on
Commit
•
43a82b2
1
Parent(s):
a098627
add fix (maybe) + adding new languages for translator
Browse files- Dockerfile +1 -3
- gradio_app.py +18 -6
Dockerfile
CHANGED
@@ -19,10 +19,8 @@ RUN mkdir translator
|
|
19 |
RUN chmod -R 777 translator
|
20 |
|
21 |
# Installing wget and downloading model.
|
22 |
-
#RUN apt install wget -y
|
23 |
-
#RUN wget -q -O model.bin https://huggingface.co/TheBloke/WizardLM-1.0-Uncensored-Llama2-13B-GGUF/resolve/main/wizardlm-1.0-uncensored-llama2-13b.Q5_K_M.gguf
|
24 |
-
#RUN ls
|
25 |
ADD https://huggingface.co/TheBloke/WizardLM-1.0-Uncensored-Llama2-13B-GGUF/resolve/main/wizardlm-1.0-uncensored-llama2-13b.Q5_K_M.gguf /app/model.bin
|
|
|
26 |
# You can use other models! Or u can comment this two RUNs and include in Space/repo/Docker image own model with name "model.bin".
|
27 |
|
28 |
# Updating pip and installing everything from requirements
|
|
|
19 |
RUN chmod -R 777 translator
|
20 |
|
21 |
# Installing wget and downloading model.
|
|
|
|
|
|
|
22 |
ADD https://huggingface.co/TheBloke/WizardLM-1.0-Uncensored-Llama2-13B-GGUF/resolve/main/wizardlm-1.0-uncensored-llama2-13b.Q5_K_M.gguf /app/model.bin
|
23 |
+
RUN chmod -R 777 /app/model.bin
|
24 |
# You can use other models! Or u can comment this two RUNs and include in Space/repo/Docker image own model with name "model.bin".
|
25 |
|
26 |
# Updating pip and installing everything from requirements
|
gradio_app.py
CHANGED
@@ -23,8 +23,7 @@ print("! INITING DONE !")
|
|
23 |
# Preparing things to work
|
24 |
translator_tokenizer.src_lang = "en"
|
25 |
title = "llama.cpp API"
|
26 |
-
desc = '''<
|
27 |
-
<h1>Hello, world!</h1>
|
28 |
This is showcase how to make own server with Llama2 model.<br>
|
29 |
I'm using here 7b model just for example. Also here's only CPU power.<br>
|
30 |
But you can use GPU power as well!<br>
|
@@ -37,6 +36,21 @@ Or you can once follow steps in Dockerfile and try it on your machine, not in Do
|
|
37 |
<br>''' + f"Memory used: {psutil.virtual_memory()[2]}<br>" + '''
|
38 |
<script>document.write("<b>URL of space:</b> "+window.location.href);</script>'''
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Loading prompt
|
41 |
with open('system.prompt', 'r', encoding='utf-8') as f:
|
42 |
prompt = f.read()
|
@@ -54,9 +68,7 @@ def generate_answer(request: str, max_tokens: int = 256, language: str = "en", c
|
|
54 |
try:
|
55 |
output = llm(userPrompt, max_tokens=maxTokens, stop=["User:"], echo=False)
|
56 |
text = output["choices"][0]["text"]
|
57 |
-
|
58 |
-
# russian (ru), ukranian (uk), chinese (zh)
|
59 |
-
if language in ["ru", "uk", "zh"]:
|
60 |
encoded_input = translator_tokenizer(text, return_tensors="pt")
|
61 |
generated_tokens = translator_model.generate(
|
62 |
**encoded_input, forced_bos_token_id=translator_tokenizer.get_lang_id(language)
|
@@ -76,7 +88,7 @@ demo = gr.Interface(
|
|
76 |
inputs=[
|
77 |
gr.components.Textbox(label="Input"),
|
78 |
gr.components.Number(value=256),
|
79 |
-
gr.components.Dropdown(label="Target Language", value="en", choices=["en"
|
80 |
gr.components.Textbox(label="Custom system prompt"),
|
81 |
],
|
82 |
outputs=["text"],
|
|
|
23 |
# Preparing things to work
|
24 |
translator_tokenizer.src_lang = "en"
|
25 |
title = "llama.cpp API"
|
26 |
+
desc = '''<h1>Hello, world!</h1>
|
|
|
27 |
This is showcase how to make own server with Llama2 model.<br>
|
28 |
I'm using here 7b model just for example. Also here's only CPU power.<br>
|
29 |
But you can use GPU power as well!<br>
|
|
|
36 |
<br>''' + f"Memory used: {psutil.virtual_memory()[2]}<br>" + '''
|
37 |
<script>document.write("<b>URL of space:</b> "+window.location.href);</script>'''
|
38 |
|
39 |
+
'''
|
40 |
+
# Defining languages for translator (i just chose popular on my opinion languages!!!)
|
41 |
+
ru - Russian
|
42 |
+
uk - Ukranian
|
43 |
+
zh - Chinese
|
44 |
+
de - German
|
45 |
+
fr - French
|
46 |
+
hi - Hindi
|
47 |
+
it - Italian
|
48 |
+
ja - Japanese
|
49 |
+
es - Spanish
|
50 |
+
ar - Arabic
|
51 |
+
'''
|
52 |
+
languages = ["ru", "uk", "zh", "de", "fr", "hi", "it", "ja", "es", "ar"]
|
53 |
+
|
54 |
# Loading prompt
|
55 |
with open('system.prompt', 'r', encoding='utf-8') as f:
|
56 |
prompt = f.read()
|
|
|
68 |
try:
|
69 |
output = llm(userPrompt, max_tokens=maxTokens, stop=["User:"], echo=False)
|
70 |
text = output["choices"][0]["text"]
|
71 |
+
if language in languages:
|
|
|
|
|
72 |
encoded_input = translator_tokenizer(text, return_tensors="pt")
|
73 |
generated_tokens = translator_model.generate(
|
74 |
**encoded_input, forced_bos_token_id=translator_tokenizer.get_lang_id(language)
|
|
|
88 |
inputs=[
|
89 |
gr.components.Textbox(label="Input"),
|
90 |
gr.components.Number(value=256),
|
91 |
+
gr.components.Dropdown(label="Target Language", value="en", choices=["en"]+languages),
|
92 |
gr.components.Textbox(label="Custom system prompt"),
|
93 |
],
|
94 |
outputs=["text"],
|