Filip
commited on
Commit
·
d5c72cc
1
Parent(s):
9f53e96
update
Browse files- app.py +44 -60
- packages.txt +1 -0
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,65 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
yield response
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
"""
|
| 45 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 46 |
-
"""
|
| 47 |
demo = gr.ChatInterface(
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 53 |
-
gr.Slider(
|
| 54 |
-
minimum=0.1,
|
| 55 |
-
maximum=1.0,
|
| 56 |
-
value=0.95,
|
| 57 |
-
step=0.05,
|
| 58 |
-
label="Top-p (nucleus sampling)",
|
| 59 |
-
),
|
| 60 |
-
],
|
| 61 |
)
|
| 62 |
|
| 63 |
-
|
| 64 |
if __name__ == "__main__":
|
| 65 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
def load_model():
|
| 6 |
+
# Download the model from HuggingFace
|
| 7 |
+
repo_id = "forestav/gguf_lora_model"
|
| 8 |
+
model_file = "unsloth.F16.gguf"
|
| 9 |
+
|
| 10 |
+
local_path = hf_hub_download(
|
| 11 |
+
repo_id=repo_id,
|
| 12 |
+
filename=model_file
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Initialize the model
|
| 16 |
+
model = Llama(
|
| 17 |
+
model_path=local_path,
|
| 18 |
+
n_ctx=2048,
|
| 19 |
+
n_threads=8
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return model
|
| 23 |
+
|
| 24 |
+
def generate_response(message, history):
|
| 25 |
+
# Generate response
|
| 26 |
+
response = model.create_chat_completion(
|
| 27 |
+
messages=[
|
| 28 |
+
{"role": "user", "content": message}
|
| 29 |
+
],
|
| 30 |
+
max_tokens=512,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
top_p=0.95,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
return response['choices'][0]['message']['content']
|
| 36 |
+
|
| 37 |
+
# Load model globally
|
| 38 |
+
model = load_model()
|
| 39 |
+
|
| 40 |
+
# Create Gradio interface with updated parameters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
demo = gr.ChatInterface(
|
| 42 |
+
fn=generate_response,
|
| 43 |
+
title="Your GGUF Model Chat",
|
| 44 |
+
description="A conversational AI model using GGUF format",
|
| 45 |
+
examples=["Continue the fibonacci sequence: 1, 1, 2, 3, 5, 8,"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
|
|
|
| 48 |
if __name__ == "__main__":
|
| 49 |
+
demo.launch()
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
build-essential
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
huggingface_hub==0.25.2
|
| 2 |
gradio
|
| 3 |
-
|
|
|
|
| 1 |
huggingface_hub==0.25.2
|
| 2 |
gradio
|
| 3 |
+
llama-cpp-python
|