Ankitajadhav commited on
Commit
af4db7d
1 Parent(s): 3d64808

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -4,6 +4,10 @@ from llama_cpp import Llama
4
  from huggingface_hub import hf_hub_download
5
  import chromadb
6
  from sentence_transformers import SentenceTransformer
 
 
 
 
7
 
8
  # Initialize the Llama model
9
  llm = Llama(
@@ -52,7 +56,7 @@ def generate_text(
52
  input_prompt += f"{interaction[0]} [/INST] {interaction[1]} </s><s> [INST] "
53
  input_prompt += f"{message} [/INST] "
54
 
55
- print("Input prompt:", input_prompt) # Debugging output
56
 
57
  temp = ""
58
  output = llm(
@@ -67,30 +71,29 @@ def generate_text(
67
  )
68
  for out in output:
69
  temp += out["choices"][0]["text"]
 
70
  yield temp
71
 
72
  # Define the Gradio interface
73
- demo = gr.ChatInterface(
74
- generate_text,
75
- title="llama-cpp-python on GPU with ChromaDB",
76
- description="Running LLM with context retrieval from ChromaDB",
77
  examples=[
78
  ["I have leftover rice, what can I make out of it?"],
79
  ["Can I make lunch for two people with this?"],
80
  ],
81
- cache_examples=False,
82
- retry_btn=None,
83
- undo_btn="Delete Previous",
84
- clear_btn="Clear",
85
- additional_inputs=[
86
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
87
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
88
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
89
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
90
  ],
 
 
91
  )
92
 
93
  if __name__ == "__main__":
94
  demo.launch()
95
-
96
-
 
4
  from huggingface_hub import hf_hub_download
5
  import chromadb
6
  from sentence_transformers import SentenceTransformer
7
+ import logging
8
+
9
+ # Initialize logging
10
+ logging.basicConfig(level=logging.INFO)
11
 
12
  # Initialize the Llama model
13
  llm = Llama(
 
56
  input_prompt += f"{interaction[0]} [/INST] {interaction[1]} </s><s> [INST] "
57
  input_prompt += f"{message} [/INST] "
58
 
59
+ logging.info("Input prompt:\n%s", input_prompt) # Debugging output
60
 
61
  temp = ""
62
  output = llm(
 
71
  )
72
  for out in output:
73
  temp += out["choices"][0]["text"]
74
+ logging.info("Model output:\n%s", temp) # Log model output
75
  yield temp
76
 
77
  # Define the Gradio interface
78
+ demo = gr.Interface(
79
+ fn=generate_text,
80
+ title="LLM Chatbot with ChromaDB Integration",
81
+ description="Generate responses based on context and user queries.",
82
  examples=[
83
  ["I have leftover rice, what can I make out of it?"],
84
  ["Can I make lunch for two people with this?"],
85
  ],
86
+ inputs=[
87
+ gr.Textbox(label="Message"),
88
+ gr.Textbox(label="System message", default="You are a friendly Chatbot."),
89
+ gr.Textbox(label="History", default="[('USER', 'Hi there!')]"),
90
+ gr.Slider(minimum=1, maximum=2048, step=1, default=512, label="Max new tokens"),
91
+ gr.Slider(minimum=0.1, maximum=4.0, step=0.1, default=0.7, label="Temperature"),
92
+ gr.Slider(minimum=0.1, maximum=1.0, step=0.05, default=0.95, label="Top-p (nucleus sampling)"),
 
 
93
  ],
94
+ outputs=gr.Textbox(label="Response"),
95
+ live=True,
96
  )
97
 
98
  if __name__ == "__main__":
99
  demo.launch()