Spaces:
Runtime error
Runtime error
Commit
·
f617ed0
1
Parent(s):
4ddc3dc
model path
Browse files- app.py +45 -61
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,64 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
|
| 5 |
+
# Replace with your actual HF model repo and filename
|
| 6 |
+
model_repo = "AravindKumarRajendran/WhiZ-gemma-3n-4b"
|
| 7 |
+
model_filename = "gemma-3n-4b-it-finetune.Q8_0.gguf" # Exact GGUF file name in repo
|
| 8 |
+
|
| 9 |
+
# Download GGUF model from HF Hub (caches locally)
|
| 10 |
+
model_path = hf_hub_download(repo_id=model_repo, filename=model_filename)
|
| 11 |
+
|
| 12 |
+
# Load model with llama-cpp
|
| 13 |
+
llm = Llama(
|
| 14 |
+
model_path=model_path,
|
| 15 |
+
n_ctx=2048,
|
| 16 |
+
n_threads=4,
|
| 17 |
+
n_batch=64,
|
| 18 |
+
verbose=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
+
# Chat handler
|
| 22 |
+
def chat_with_model(history, user_input):
|
| 23 |
+
history.append(("🧑💻: " + user_input, ""))
|
| 24 |
+
prompt = f"{user_input} தமிழில் பதிலளி:"
|
| 25 |
+
|
| 26 |
+
output = llm(
|
| 27 |
+
prompt,
|
| 28 |
+
max_tokens=128,
|
| 29 |
+
temperature=0.7,
|
| 30 |
+
stop=["</s>"],
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
reply = output["choices"][0]["text"].strip()
|
| 34 |
+
history[-1] = (history[-1][0], "🤖: " + reply)
|
| 35 |
+
return history, ""
|
| 36 |
+
|
| 37 |
+
# Gradio UI
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown("## 🗣️ தமிழில் உரையாடல் (Tamil Chatbot - GGUF on CPU)")
|
| 40 |
+
chatbot = gr.Chatbot()
|
| 41 |
+
msg = gr.Textbox(label="உங்கள் செய்தி", placeholder="Type your message...")
|
| 42 |
+
clear = gr.Button("🧹 Clear Chat")
|
| 43 |
+
state = gr.State([])
|
| 44 |
+
|
| 45 |
+
msg.submit(chat_with_model, [state, msg], [chatbot, msg])
|
| 46 |
+
clear.click(lambda: ([], ""), None, [chatbot, msg, state])
|
| 47 |
+
|
| 48 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
-
huggingface_hub==0.25.2
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.25.2
|
| 2 |
+
llama-cpp-python==0.2.58
|
| 3 |
+
gradio
|