mrcuddle commited on
Commit
bc7da9a
·
verified ·
1 Parent(s): adaaf5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -1,23 +1,28 @@
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,7 +30,7 @@ def chatbot(message, history):
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")
 
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")