Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
import spaces
|
5 |
|
6 |
-
#
|
7 |
-
model_name = "
|
8 |
-
|
|
|
9 |
|
10 |
-
# Initialize the LLM model
|
11 |
-
llm = LLM(model=model_name, tokenizer_mode="mistral", config_format="mistral", load_format="mistral")
|
12 |
-
|
13 |
-
@spaces.GPU
|
14 |
# Define the chatbot function
|
15 |
def chatbot(message, history):
|
16 |
-
#
|
17 |
-
|
18 |
-
{
|
19 |
-
"role": "user",
|
20 |
-
"content": message
|
21 |
-
},
|
22 |
-
]
|
23 |
|
24 |
# Generate the response
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
# Append the response to the history
|
29 |
history.append((message, response))
|
@@ -31,7 +25,7 @@ def chatbot(message, history):
|
|
31 |
|
32 |
# Create the Gradio interface
|
33 |
with gr.Blocks() as demo:
|
34 |
-
gr.Markdown("## Chatbot using
|
35 |
|
36 |
# Create a Chatbot component
|
37 |
chatbot = gr.Chatbot([], elem_id="chatbot")
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
|
|
4 |
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_name = "mrcuddle/Ministral-Instruct-2410-8B-DPO-RP"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
|
|
|
|
|
|
|
|
|
10 |
# Define the chatbot function
|
11 |
def chatbot(message, history):
|
12 |
+
# Tokenize the input
|
13 |
+
inputs = tokenizer(message, return_tensors="pt")
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Generate the response
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model.generate(**inputs)
|
18 |
+
|
19 |
+
# Decode the response
|
20 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
|
22 |
# Append the response to the history
|
23 |
history.append((message, response))
|
|
|
25 |
|
26 |
# Create the Gradio interface
|
27 |
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## Chatbot using mrcuddle/Ministral-Instruct-2410-8B-DPO-RP")
|
29 |
|
30 |
# Create a Chatbot component
|
31 |
chatbot = gr.Chatbot([], elem_id="chatbot")
|