Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import copy
|
4 |
+
import time
|
5 |
+
import llama_cpp
|
6 |
+
from llama_cpp import Llama
|
7 |
+
from huggingface_hub import hf_hub_download
|
8 |
+
|
9 |
+
llm = Llama(
|
10 |
+
model_path=hf_hub_download(
|
11 |
+
repo_id="praveenpankaj/aksara_1_unsloth_q4",
|
12 |
+
filename="aksara_-unsloth.Q4_K_M.gguf",
|
13 |
+
),
|
14 |
+
n_ctx=1024,
|
15 |
+
)
|
16 |
+
|
17 |
+
history = []
|
18 |
+
|
19 |
+
def generate_text(message, history):
|
20 |
+
temp = ""
|
21 |
+
input_prompt = "Ask akṣara anything on Agriculture in the Global South.\n"
|
22 |
+
for interaction in history:
|
23 |
+
input_prompt += "[|Umano|] " + interaction[0] + "\n"
|
24 |
+
input_prompt += "[|Assistente|]" + interaction[1]
|
25 |
+
|
26 |
+
input_prompt += "[|Umano|] " + message + "\n[|Assistente|]"
|
27 |
+
|
28 |
+
print(input_prompt)
|
29 |
+
|
30 |
+
output = llm(
|
31 |
+
input_prompt,
|
32 |
+
temperature=0.15,
|
33 |
+
top_p=0.1,
|
34 |
+
top_k=40,
|
35 |
+
repeat_penalty=1.1,
|
36 |
+
max_tokens=1024,
|
37 |
+
stop=[
|
38 |
+
"[|Umano|]",
|
39 |
+
"[|Assistente|]",
|
40 |
+
],
|
41 |
+
stream=True,
|
42 |
+
)
|
43 |
+
for out in output:
|
44 |
+
stream = copy.deepcopy(out)
|
45 |
+
temp += stream["choices"][0]["text"]
|
46 |
+
yield temp
|
47 |
+
|
48 |
+
history = ["init", input_prompt]
|
49 |
+
|
50 |
+
|
51 |
+
demo = gr.ChatInterface(
|
52 |
+
generate_text,
|
53 |
+
title="akṣara running on CPU (quantized Q4_K)",
|
54 |
+
description="This is a quantized version of akṣara running on CPU. It is a quantized version of the original version, that is running on a CPU machine.",
|
55 |
+
examples=[
|
56 |
+
"What are the recommended NPK dosage for maize varieties?",
|
57 |
+
"Heavy rains are predicted next week. Is my rice crop ready for this, or should I harvest early?",
|
58 |
+
"What crops can I grow during the dry season to use water more efficiently?"
|
59 |
+
],
|
60 |
+
cache_examples=False,
|
61 |
+
retry_btn=None,
|
62 |
+
undo_btn="Delete Previous",
|
63 |
+
clear_btn="Clear",
|
64 |
+
)
|
65 |
+
demo.queue(concurrency_count=1, max_size=5)
|
66 |
+
demo.launch()
|