mrcuddle commited on
Commit
e983684
·
verified ·
1 Parent(s): fbd0171

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -1,29 +1,23 @@
1
  import gradio as gr
2
- from vllm import LLM
3
- from vllm.sampling_params import SamplingParams
4
- import spaces
5
 
6
- # Define the model and sampling parameters
7
- model_name = "mistralai/Ministral-8B-Instruct-2410"
8
- sampling_params = SamplingParams(max_tokens=8192)
 
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
- # Prepare the messages for the model
17
- messages = [
18
- {
19
- "role": "user",
20
- "content": message
21
- },
22
- ]
23
 
24
  # Generate the response
25
- outputs = llm.chat(messages, sampling_params=sampling_params)
26
- response = outputs[0].outputs[0].text
 
 
 
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 mistralai/Ministral-8B-Instruct-2410")
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")