Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
model_name = "
|
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 |
-
#
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Generate the response
|
16 |
-
|
17 |
-
|
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,7 +30,7 @@ def chatbot(message, history):
|
|
25 |
|
26 |
# Create the Gradio interface
|
27 |
with gr.Blocks() as demo:
|
28 |
-
gr.Markdown("## Chatbot using
|
29 |
|
30 |
# Create a Chatbot component
|
31 |
chatbot = gr.Chatbot([], elem_id="chatbot")
|
|
|
1 |
import gradio as gr
|
2 |
+
from vllm import LLM
|
3 |
+
from vllm.sampling_params import SamplingParams
|
4 |
+
import spaces
|
5 |
+
# Define the model and sampling parameters
|
6 |
+
model_name = "mistralai/Ministral-8B-Instruct-2410"
|
7 |
+
sampling_params = SamplingParams(max_tokens=8192)
|
8 |
|
9 |
+
# Initialize the LLM model
|
10 |
+
llm = LLM(model=model_name, tokenizer_mode="mistral", config_format="mistral", load_format="mistral")
|
|
|
|
|
11 |
|
12 |
+
@spaces.GPU
|
13 |
# Define the chatbot function
|
14 |
def chatbot(message, history):
|
15 |
+
# Prepare the messages for the model
|
16 |
+
messages = [
|
17 |
+
{
|
18 |
+
"role": "user",
|
19 |
+
"content": message
|
20 |
+
},
|
21 |
+
]
|
22 |
|
23 |
# Generate the response
|
24 |
+
outputs = llm.chat(messages, sampling_params=sampling_params)
|
25 |
+
response = outputs[0].outputs[0].text
|
|
|
|
|
|
|
26 |
|
27 |
# Append the response to the history
|
28 |
history.append((message, response))
|
|
|
30 |
|
31 |
# Create the Gradio interface
|
32 |
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("## Chatbot using mistralai/Ministral-8B-Instruct-2410")
|
34 |
|
35 |
# Create a Chatbot component
|
36 |
chatbot = gr.Chatbot([], elem_id="chatbot")
|