Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
|
2 |
-
!nvcc --version
|
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 |
-
|
|
|
1 |
|
|
|
2 |
|
3 |
+
from llamafactory.chat import ChatModel
|
4 |
+
import gradio as gr
|
5 |
|
6 |
+
# Step 1: Load your model
|
7 |
+
args = dict(
|
8 |
+
model_name_or_path="unsloth/llama-3-8b-Instruct-bnb-4bit",
|
9 |
+
adapter_name_or_path="enzer1992/AI-Guru",
|
10 |
+
template="llama3",
|
11 |
+
finetuning_type="lora",
|
12 |
+
quantization_bit=4,
|
13 |
+
device="cpu", # Forces CPU usage
|
14 |
+
)
|
15 |
+
chat_model = ChatModel(args)
|
16 |
|
17 |
+
# Step 2: Create a function for chatting
|
18 |
+
def chat(user_input, history):
|
19 |
+
messages = history + [{"role": "user", "content": user_input}]
|
20 |
+
response = ""
|
21 |
+
for new_text in chat_model.stream_chat(messages):
|
22 |
+
response += new_text
|
23 |
+
history.append({"role": "user", "content": user_input})
|
24 |
+
history.append({"role": "assistant", "content": response})
|
25 |
+
return response, history
|
26 |
|
27 |
+
# Step 3: Create a simple interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=chat,
|
30 |
+
inputs=[gr.Textbox(label="Your Message"), gr.State()],
|
31 |
+
outputs=[gr.Textbox(label="AI Response"), gr.State()],
|
32 |
+
title="AI Guru Chatbot"
|
33 |
+
)
|
34 |
|
35 |
+
iface.launch()
|