desert
commited on
Commit
•
01945bd
1
Parent(s):
f61a70f
init inference
Browse files- app.py +53 -51
- requirements.txt +1 -2
app.py
CHANGED
@@ -1,53 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
model
|
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 |
-
# Create the Gradio interface
|
42 |
-
demo = gr.ChatInterface(
|
43 |
-
respond,
|
44 |
-
additional_inputs=[
|
45 |
-
gr.Textbox(value="You are a friendly chatbot.", label="System message"),
|
46 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
47 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
48 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
49 |
-
],
|
50 |
-
)
|
51 |
-
|
52 |
-
if __name__ == "__main__":
|
53 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from llama_cpp import Llama
|
3 |
+
|
4 |
+
# Path to the GGUF model file
|
5 |
+
model_path = "Mat17892/lora_llama_gguf_g14/model.gguf" # Update this path to your model
|
6 |
+
|
7 |
+
# Load the GGUF model using llama-cpp-python
|
8 |
+
print("Loading model...")
|
9 |
+
llm = Llama(model_path=model_path, n_ctx=2048, n_threads=8) # Adjust threads as needed
|
10 |
+
print("Model loaded!")
|
11 |
+
|
12 |
+
# Chat function
|
13 |
+
def chat_with_model(user_input, chat_history):
|
14 |
+
"""
|
15 |
+
Process user input and generate a response from the model.
|
16 |
+
:param user_input: User's input string
|
17 |
+
:param chat_history: Conversation history
|
18 |
+
:return: Updated chat history
|
19 |
+
"""
|
20 |
+
# Format chat history for the Llama model
|
21 |
+
prompt = ""
|
22 |
+
for turn in chat_history:
|
23 |
+
prompt += f"User: {turn['user']}\nAI: {turn['ai']}\n"
|
24 |
+
prompt += f"User: {user_input}\nAI:"
|
25 |
+
|
26 |
+
# Generate response from the model
|
27 |
+
response = llm(prompt)["choices"][0]["text"].strip()
|
28 |
+
|
29 |
+
# Update chat history
|
30 |
+
chat_history.append({"user": user_input, "ai": response})
|
31 |
+
return chat_history, chat_history
|
32 |
+
|
33 |
+
# Gradio UI
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("# 🦙 LLaMA GGUF Chatbot")
|
36 |
+
chat_box = gr.Chatbot(label="Chat with the GGUF Model")
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column(scale=4):
|
40 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type a message...")
|
41 |
+
with gr.Column(scale=1):
|
42 |
+
submit_btn = gr.Button("Send")
|
43 |
+
|
44 |
+
chat_history = gr.State([])
|
45 |
+
|
46 |
+
# Link components
|
47 |
+
submit_btn.click(
|
48 |
+
chat_with_model,
|
49 |
+
inputs=[user_input, chat_history],
|
50 |
+
outputs=[chat_box, chat_history],
|
51 |
+
show_progress=True,
|
52 |
)
|
53 |
+
|
54 |
+
# Launch the app
|
55 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
gradio
|
3 |
-
|
4 |
-
torch
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
gradio
|
3 |
+
llama-cpp-python
|
|