Dread2Poor commited on
Commit
b873ded
·
verified ·
1 Parent(s): e94b0d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from llama_cpp import Llama
2
  from huggingface_hub import hf_hub_download
 
3
 
4
  hf_hub_download(repo_id="Dread2Poor/Killamanjaro-8B-Model_Stock-Q4_K_M-GGUF", filename="killamanjaro-8b-model_stock-q4_k_m.gguf", repo_type="model", local_dir=".")
5
 
@@ -31,6 +32,8 @@ def chat_with_model(user_input):
31
  """
32
  Engage in a chat with the model using the provided user input.
33
  """
 
 
34
  # Append user input to history
35
  history.append({"role": "user", "content": user_input})
36
 
@@ -48,11 +51,27 @@ def chat_with_model(user_input):
48
 
49
  return assistant_reply
50
 
51
- # Example usage
52
- if __name__ == "__main__":
53
- while True:
54
- user_input = input("You: ")
55
- if user_input.lower() in ["exit", "quit"]:
56
- break
57
- reply = chat_with_model(user_input)
58
- print("Assistant:", reply)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from llama_cpp import Llama
2
  from huggingface_hub import hf_hub_download
3
+ import gradio as gr
4
 
5
  hf_hub_download(repo_id="Dread2Poor/Killamanjaro-8B-Model_Stock-Q4_K_M-GGUF", filename="killamanjaro-8b-model_stock-q4_k_m.gguf", repo_type="model", local_dir=".")
6
 
 
32
  """
33
  Engage in a chat with the model using the provided user input.
34
  """
35
+ global history
36
+
37
  # Append user input to history
38
  history.append({"role": "user", "content": user_input})
39
 
 
51
 
52
  return assistant_reply
53
 
54
+ def reset_history():
55
+ """
56
+ Reset the chat history to the initial state.
57
+ """
58
+ global history
59
+ history = [{"role": "system", "content": system_prompt}]
60
+ return gr.update(value=""), gr.update(value=[])
61
+
62
+ # Create Gradio interface
63
+ with gr.Blocks() as demo:
64
+ chatbot = gr.Chatbot()
65
+ with gr.Row():
66
+ with gr.Column(scale=4):
67
+ user_input = gr.Textbox(show_label=False, placeholder="Type your message here...")
68
+ with gr.Column(scale=1):
69
+ submit_btn = gr.Button("Send")
70
+ with gr.Row():
71
+ clear_btn = gr.Button("Clear Chat")
72
+
73
+ submit_btn.click(chat_with_model, inputs=user_input, outputs=chatbot)
74
+ clear_btn.click(reset_history, inputs=[], outputs=[user_input, chatbot])
75
+
76
+ # Launch the interface
77
+ demo.launch()