Spaces:
Sleeping
Sleeping
Anish Asokan
commited on
Commit
•
03a3635
1
Parent(s):
8f7eb5d
fixes
Browse files- app.py +94 -23
- bad.requirements.txt +0 -2
- css/index.css +9 -0
- models/.gitkeep +0 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,32 +1,103 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
"""
|
7 |
-
def greet(name):
|
8 |
-
return "Hello " + name + "!!"
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
""
|
13 |
|
14 |
-
|
|
|
|
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
"""
|
17 |
-
# reference: https://medium.com/@rowel/gradio-hugging-face-for-rapid-deep-learning-app-development-709a78e7ccc0
|
18 |
-
# https://huggingface.co/spaces/rowel/22k-image-classification
|
19 |
-
|
20 |
-
pipe = pipeline(task="conversational",
|
21 |
-
# model for 22k-category classification
|
22 |
-
model="abhinand/malayalam-llama-7b-instruct-v0.1")
|
23 |
-
|
24 |
-
gr.Interface.from_pipeline(pipe,
|
25 |
-
title="Chat",
|
26 |
-
description="Ask your questions in malayalam",
|
27 |
-
examples = ['കേരളത്തിലെ ജില്ലകൾ ഏതെല്ലാം ?',
|
28 |
-
'കേരളത്തിന്റെ തലസ്ഥാനം എവിടെയാണ് ?',],
|
29 |
-
).launch(inbrowser=True)
|
30 |
-
"""
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from gpt4all import GPT4All
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
|
5 |
+
title = "Malayalam-llama-7b-instruct-v0.1 (CPU Demo)"
|
6 |
|
7 |
+
description = """
|
8 |
+
[Malayalam LLaMA 7B Instruct v0.1](https://huggingface.co/abhinand/malayalam-llama-7b-instruct-v0.1)
|
9 |
+
Running on free CPU hardware. Suggest duplicating this space to run without a queue.
|
10 |
+
**Note:** The inference is quite slow as it is running on CPU.
|
11 |
"""
|
|
|
|
|
12 |
|
13 |
+
model_path = "models"
|
14 |
+
model_name = "malayalam-llama-7b-instruct-v0.1.Q5_K_M.gguf"
|
15 |
+
hf_hub_download(repo_id="abhinand/malayalam-llama-7b-instruct-v0.1-GGUF", filename=model_name, local_dir=model_path, local_dir_use_symlinks=False)
|
16 |
|
17 |
+
print("Start the model init process")
|
18 |
+
model = model = GPT4All(model_name, model_path, allow_download = False, device="cpu")
|
19 |
+
print("Finish the model init process")
|
20 |
|
21 |
+
model.config["promptTemplate"] = """ഞാൻ ഒരു സഹായകരവും, സത്യസന്ധവും ആയ നിർമ്മിത ബുദ്ധി ആണ്. ഞാൻ എപ്പോഴും നിങ്ങളുടെ സുരക്ഷയെ മുൻനിർത്തി കഴിയുന്നത്ര സഹായകരമായ പ്രതികരണം നൽകുന്നു. നിങ്ങളുടെ പ്രതികരണം മറ്റുള്ളവർക്ക് ഏതൊരു വിധത്തിലും ദോഷം, ഉപദ്രവം, അപകടം ഉണ്ടാകുന്നത് അല്ല എന്ന് നിങ്ങൾ ഉറപ്പുവരുത്തണം. നിങ്ങളുടെ പ്രതികരണത്തിന്റെ ദോഷത്തെ കുറിച്ച് നിങ്ങൾക്ക് ബോധ്യം ഇല്ലെങ്കിൽ, നിങ്ങൾക്ക് ലഭിക്കുന്ന നിർദ്ദേശങ്ങൾ നിങ്ങൾ മറ്റുള്ളവരുമായി പങ്കുവെക്കാതിരിക്കുക.
|
22 |
+
|
23 |
+
### Instruction:
|
24 |
+
{0}
|
25 |
+
|
26 |
+
### Response:
|
27 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
model.config["systemPrompt"] = ""
|
30 |
+
model._is_chat_session_activated = False
|
31 |
+
|
32 |
+
max_new_tokens = 2048
|
33 |
+
|
34 |
+
def generator(message, history, temperature, top_p, top_k):
|
35 |
+
prompt = ""
|
36 |
+
for user_message, assistant_message in history:
|
37 |
+
prompt += model.config["promptTemplate"].format(user_message)
|
38 |
+
|
39 |
+
prompt += model.config["promptTemplate"].format(message)
|
40 |
+
outputs = []
|
41 |
+
for token in model.generate(prompt=prompt, temp=temperature, top_k = top_k, top_p = top_p, max_tokens = max_new_tokens, streaming=True):
|
42 |
+
outputs.append(token)
|
43 |
+
yield "".join(outputs)
|
44 |
+
|
45 |
+
def vote(data: gr.LikeData):
|
46 |
+
if data.liked:
|
47 |
+
return
|
48 |
+
else:
|
49 |
+
return
|
50 |
+
|
51 |
+
chatbot = gr.Chatbot(bubble_full_width=False)
|
52 |
+
|
53 |
+
additional_inputs=[
|
54 |
+
gr.Slider(
|
55 |
+
label="temperature",
|
56 |
+
value=0.2,
|
57 |
+
minimum=0.0,
|
58 |
+
maximum=2.0,
|
59 |
+
step=0.05,
|
60 |
+
interactive=True,
|
61 |
+
info="Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
|
62 |
+
),
|
63 |
+
gr.Slider(
|
64 |
+
label="top_p",
|
65 |
+
value=1.0,
|
66 |
+
minimum=0.0,
|
67 |
+
maximum=1.0,
|
68 |
+
step=0.01,
|
69 |
+
interactive=True,
|
70 |
+
info="0.1 means only the tokens comprising the top 10% probability mass are considered. Suggest set to 1 and use temperature. 1 means 100% and will disable it",
|
71 |
+
),
|
72 |
+
gr.Slider(
|
73 |
+
label="top_k",
|
74 |
+
value=40,
|
75 |
+
minimum=0,
|
76 |
+
maximum=1000,
|
77 |
+
step=1,
|
78 |
+
interactive=True,
|
79 |
+
info="limits candidate tokens to a fixed number after sorting by probability. Setting it higher than the vocabulary size deactivates this limit.",
|
80 |
+
)
|
81 |
+
]
|
82 |
+
|
83 |
+
iface = gr.ChatInterface(
|
84 |
+
fn = generator,
|
85 |
+
title=title,
|
86 |
+
description = description,
|
87 |
+
chatbot=chatbot,
|
88 |
+
additional_inputs=additional_inputs,
|
89 |
+
examples=[
|
90 |
+
["നിങ്ങൾ ആരാണ��� ?"],
|
91 |
+
["நான் பெரிய பணக்காரன் இல்லை, லேட்டஸ்ட் iPhone-இல் நிறைய பணம் செலவழிக்க வேண்டுமா?"],
|
92 |
+
["பட்டியலை வரிசைப்படுத்த பைதான் செயல்பாட்டை எழுதவும்."],
|
93 |
+
["சிவப்பும் மஞ்சளும் கலந்தால் என்ன நிறமாக இருக்கும்?"],
|
94 |
+
["விரைவாக தூங்குவது எப்படி?"]
|
95 |
+
]
|
96 |
+
)
|
97 |
+
|
98 |
+
with gr.Blocks(css="css/index.css") as demo:
|
99 |
+
chatbot.like(vote, None, None)
|
100 |
+
iface.render()
|
101 |
+
|
102 |
+
if __name__ == "__main__":
|
103 |
+
demo.queue(max_size=3).launch()
|
bad.requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
torch
|
2 |
-
transformers
|
|
|
|
|
|
css/index.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
}
|
4 |
+
|
5 |
+
.contain {
|
6 |
+
max-width: 1000px;
|
7 |
+
margin: auto;
|
8 |
+
padding-top: 1.5rem;
|
9 |
+
}
|
models/.gitkeep
ADDED
File without changes
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gpt4all==2.0.2
|