APPenner commited on
Commit
480628e
·
verified ·
1 Parent(s): 165f822

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -31
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import json
3
  from huggingface_hub import InferenceClient
4
- from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
  # Initialize the Hugging Face inference client
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
@@ -9,28 +8,29 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
  # Memory functions for remembering user's name
10
  memory = {}
11
 
12
- # Load memory from a file, return empty dict if file is missing or corrupted
13
- def load_memory():
14
- try:
15
- with open("memory.json", "r") as f:
16
- return json.load(f)
17
- except (FileNotFoundError, json.JSONDecodeError):
18
- return {} # Return an empty dictionary if the file is missing or corrupted
19
-
20
- # Save memory to a file
21
- def save_memory():
22
- with open("memory.json", "w") as f:
23
- json.dump(memory, f)
24
-
25
- # Function to remember a name
26
  def remember(name, value):
27
  memory[name] = value
28
- save_memory()
29
 
30
- # Function to recall a name
31
  def recall(name):
32
  return memory.get(name, None)
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Respond function, processing messages and remembering names
35
  def respond(
36
  message,
@@ -95,18 +95,4 @@ demo = gr.ChatInterface(
95
  )
96
 
97
  if __name__ == "__main__":
98
- # Load memory at the start
99
- memory = load_memory()
100
  demo.launch()
101
-
102
- # Model setup using transformers
103
- model_name = "APPenner/Aven" # Ensure this is the correct model path
104
- tokenizer = AutoTokenizer.from_pretrained(model_name)
105
- model = AutoModelForCausalLM.from_pretrained(model_name)
106
-
107
- # Logic for generating responses using the model
108
- def generate_response(prompt):
109
- inputs = tokenizer(prompt, return_tensors="pt")
110
- outputs = model.generate(**inputs)
111
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
112
- return response
 
1
  import gradio as gr
2
  import json
3
  from huggingface_hub import InferenceClient
 
4
 
5
  # Initialize the Hugging Face inference client
6
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
8
  # Memory functions for remembering user's name
9
  memory = {}
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def remember(name, value):
12
  memory[name] = value
13
+ save_memory() # Save memory after remembering the name
14
 
 
15
  def recall(name):
16
  return memory.get(name, None)
17
 
18
+ # Save the memory to a file
19
+ def save_memory():
20
+ with open('memory.json', 'w') as f:
21
+ json.dump(memory, f)
22
+
23
+ # Load the memory from a file
24
+ def load_memory():
25
+ try:
26
+ with open('memory.json', 'r') as f:
27
+ return json.load(f)
28
+ except (FileNotFoundError, json.JSONDecodeError):
29
+ return {} # Return empty memory if no file or invalid file
30
+
31
+ # Load the memory when the app starts
32
+ memory = load_memory()
33
+
34
  # Respond function, processing messages and remembering names
35
  def respond(
36
  message,
 
95
  )
96
 
97
  if __name__ == "__main__":
 
 
98
  demo.launch()