bmas10 commited on
Commit
03a30d8
·
verified ·
1 Parent(s): 3818808

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -19,7 +19,11 @@ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float
19
  def chat(input_text, history=[]):
20
  history.append(input_text)
21
  prompt = "\n".join(history) + "\nAI:" # Simple conversational format
22
- inputs = tokenizer(prompt, retur
 
 
 
 
23
 
24
  """
25
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -63,7 +67,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
63
  """
64
 
65
  demo = gr.ChatInterface(
66
- chat_response,
67
  additional_inputs=[
68
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
69
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
 
19
  def chat(input_text, history=[]):
20
  history.append(input_text)
21
  prompt = "\n".join(history) + "\nAI:" # Simple conversational format
22
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
23
+ output = model.generate(**inputs, max_length=512, pad_token_id=tokenizer.eos_token_id)
24
+ response = tokenizer.decode(output[:, inputs.input_ids.shape[-1]:][0], skip_special_tokens=True)
25
+ history.append(f"AI: {response}")
26
+ return response, history
27
 
28
  """
29
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
67
  """
68
 
69
  demo = gr.ChatInterface(
70
+ chat,
71
  additional_inputs=[
72
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
73
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")