enzer1992 commited on
Commit
865ddb2
·
verified ·
1 Parent(s): 4cbb416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -1,35 +1,35 @@
1
 
2
- !nvcc --version
3
 
4
- # from llamafactory.chat import ChatModel
5
- # import gradio as gr
6
 
7
- # # Step 1: Load your model
8
- # args = dict(
9
- # model_name_or_path="unsloth/llama-3-8b-Instruct-bnb-4bit",
10
- # adapter_name_or_path="enzer1992/AI-Guru",
11
- # template="llama3",
12
- # finetuning_type="lora",
13
- # quantization_bit=4,
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()
 
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()