desert commited on
Commit
def541d
1 Parent(s): 2936c26

init inference

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -18,26 +18,26 @@ def chat_with_model(user_input, chat_history):
18
  """
19
  Process user input and generate a response from the model.
20
  :param user_input: User's input string
21
- :param chat_history: Conversation history
22
  :return: Updated chat history
23
  """
24
- # Format chat history for the Llama model
25
  prompt = ""
26
- for turn in chat_history:
27
- prompt += f"User: {turn['user']}\nAI: {turn['ai']}\n"
28
  prompt += f"User: {user_input}\nAI:"
29
 
30
  # Generate response from the model
31
  response = llm(prompt)["choices"][0]["text"].strip()
32
 
33
- # Update chat history
34
- chat_history.append({"user": user_input, "ai": response})
35
  return chat_history, chat_history
36
 
37
  # Gradio UI
38
  with gr.Blocks() as demo:
39
  gr.Markdown("# 🦙 LLaMA GGUF Chatbot")
40
- chat_box = gr.Chatbot(label="Chat with the GGUF Model")
41
 
42
  with gr.Row():
43
  with gr.Column(scale=4):
@@ -51,7 +51,7 @@ with gr.Blocks() as demo:
51
  submit_btn.click(
52
  chat_with_model,
53
  inputs=[user_input, chat_history],
54
- outputs=[chat_box, chat_history],
55
  show_progress=True,
56
  )
57
 
 
18
  """
19
  Process user input and generate a response from the model.
20
  :param user_input: User's input string
21
+ :param chat_history: List of [user_message, ai_response] pairs
22
  :return: Updated chat history
23
  """
24
+ # Combine chat history into a single prompt
25
  prompt = ""
26
+ for user, ai in chat_history:
27
+ prompt += f"User: {user}\nAI: {ai}\n"
28
  prompt += f"User: {user_input}\nAI:"
29
 
30
  # Generate response from the model
31
  response = llm(prompt)["choices"][0]["text"].strip()
32
 
33
+ # Update chat history as a list of tuples
34
+ chat_history.append((user_input, response))
35
  return chat_history, chat_history
36
 
37
  # Gradio UI
38
  with gr.Blocks() as demo:
39
  gr.Markdown("# 🦙 LLaMA GGUF Chatbot")
40
+ chatbot = gr.Chatbot(label="Chat with the GGUF Model")
41
 
42
  with gr.Row():
43
  with gr.Column(scale=4):
 
51
  submit_btn.click(
52
  chat_with_model,
53
  inputs=[user_input, chat_history],
54
+ outputs=[chatbot, chat_history],
55
  show_progress=True,
56
  )
57