Hev832 commited on
Commit
de82ee9
·
verified ·
1 Parent(s): 660bf7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -5,7 +5,7 @@ import torch
5
  # Load the Hugging Face model and tokenizer
6
  model_name = "HuggingFaceH4/zephyr-7b-beta"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
9
 
10
  # Define custom system content
11
  custom_system_content = """
@@ -15,7 +15,7 @@ Please provide thoughtful and concise responses.
15
 
16
  # Function to generate chatbot responses
17
  def chatbot_response(user_input):
18
- inputs = tokenizer(custom_system_content + user_input, return_tensors="pt").to("cuda")
19
  outputs = model.generate(**inputs, max_length=256)
20
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
  return response[len(custom_system_content):]
@@ -28,7 +28,7 @@ with gr.Blocks() as demo:
28
  with gr.Row():
29
  with gr.Column():
30
  user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
31
- chatbot_output = gr.Textbox(label="Chatbot Response", placeholder="Chatbot will respond here...")
32
 
33
  with gr.Column():
34
  submit_btn = gr.Button("Send")
 
5
  # Load the Hugging Face model and tokenizer
6
  model_name = "HuggingFaceH4/zephyr-7b-beta"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
9
 
10
  # Define custom system content
11
  custom_system_content = """
 
15
 
16
  # Function to generate chatbot responses
17
  def chatbot_response(user_input):
18
+ inputs = tokenizer(custom_system_content + user_input, return_tensors="pt")
19
  outputs = model.generate(**inputs, max_length=256)
20
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
  return response[len(custom_system_content):]
 
28
  with gr.Row():
29
  with gr.Column():
30
  user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
31
+ chatbot_output = gr.Chatbot(label="Chatbot Response", placeholder="Chatbot will respond here...")
32
 
33
  with gr.Column():
34
  submit_btn = gr.Button("Send")