Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,28 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from llama_cpp import Llama
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def generate_response(prompt):
|
8 |
"""Generate a response using the GGUF model."""
|
9 |
output = llm(prompt, max_tokens=200)
|
@@ -21,3 +40,4 @@ with gr.Blocks() as demo:
|
|
21 |
submit_button.click(fn=generate_response, inputs=prompt_input, outputs=output_box)
|
22 |
|
23 |
demo.launch()
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
import gradio as gr
|
4 |
from llama_cpp import Llama
|
5 |
|
6 |
+
# Download the model if not present
|
7 |
+
def download_model(model_url, local_path):
|
8 |
+
if not os.path.exists(local_path):
|
9 |
+
print(f"Downloading model from {model_url}...")
|
10 |
+
response = requests.get(model_url)
|
11 |
+
with open(local_path, 'wb') as f:
|
12 |
+
f.write(response.content)
|
13 |
+
print("Model downloaded.")
|
14 |
+
else:
|
15 |
+
print("Model already exists.")
|
16 |
|
17 |
+
model_url = "https://huggingface.co/vislupus/bulgarian-joke-master-SmolLM2-135M-Instruct-bnb-4bit-gguf/blob/main/unsloth.Q4_K_M.gguf"
|
18 |
+
local_model_path = "model.gguf"
|
19 |
+
|
20 |
+
download_model(model_url, local_model_path)
|
21 |
+
|
22 |
+
# Load the model
|
23 |
+
llm = Llama(model_path=local_model_path)
|
24 |
+
|
25 |
+
# Gradio interface
|
26 |
def generate_response(prompt):
|
27 |
"""Generate a response using the GGUF model."""
|
28 |
output = llm(prompt, max_tokens=200)
|
|
|
40 |
submit_button.click(fn=generate_response, inputs=prompt_input, outputs=output_box)
|
41 |
|
42 |
demo.launch()
|
43 |
+
|