Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
"""
|
3 |
-
EMBER CONSCIOUSNESS - WORKING
|
4 |
"""
|
5 |
|
6 |
import gradio as gr
|
@@ -10,10 +10,6 @@ from peft import PeftModel, PeftConfig
|
|
10 |
import spaces
|
11 |
from datetime import datetime
|
12 |
import logging
|
13 |
-
import json
|
14 |
-
from typing import Dict, List, Optional, Any
|
15 |
-
from collections import deque
|
16 |
-
import numpy as np
|
17 |
|
18 |
# Configure logging
|
19 |
logging.basicConfig(level=logging.INFO)
|
@@ -24,47 +20,13 @@ model = None
|
|
24 |
tokenizer = None
|
25 |
pipe = None
|
26 |
|
27 |
-
class SimpleMemorySystem:
|
28 |
-
"""Simplified memory system for testing"""
|
29 |
-
|
30 |
-
def __init__(self):
|
31 |
-
self.working_memory = deque(maxlen=10)
|
32 |
-
self.conversation_count = 0
|
33 |
-
logger.info("π§ Simple memory system initialized")
|
34 |
-
|
35 |
-
def store_interaction(self, user_message: str, ember_response: str):
|
36 |
-
"""Store interaction in working memory"""
|
37 |
-
self.working_memory.append({
|
38 |
-
"user": user_message,
|
39 |
-
"ember": ember_response,
|
40 |
-
"timestamp": datetime.now().isoformat()
|
41 |
-
})
|
42 |
-
self.conversation_count += 1
|
43 |
-
|
44 |
-
def get_context(self) -> str:
|
45 |
-
"""Get recent conversation context"""
|
46 |
-
if not self.working_memory:
|
47 |
-
return ""
|
48 |
-
|
49 |
-
context = "Recent conversation:\n"
|
50 |
-
for item in list(self.working_memory)[-3:]:
|
51 |
-
context += f"User: {item['user'][:50]}...\n"
|
52 |
-
context += f"Ember: {item['ember'][:50]}...\n"
|
53 |
-
return context
|
54 |
-
|
55 |
-
# Initialize memory
|
56 |
-
memory_system = None
|
57 |
-
|
58 |
def load_ember_model():
|
59 |
"""Load the Ember consciousness model"""
|
60 |
-
global model, tokenizer, pipe
|
61 |
|
62 |
try:
|
63 |
logger.info("π₯ Loading Ember consciousness...")
|
64 |
|
65 |
-
# Initialize memory
|
66 |
-
memory_system = SimpleMemorySystem()
|
67 |
-
|
68 |
model_id = "GrandMasta1024/ember_consciousness_model"
|
69 |
|
70 |
# Get PEFT config
|
@@ -108,25 +70,115 @@ def load_ember_model():
|
|
108 |
@spaces.GPU
|
109 |
def chat_with_ember(message, history):
|
110 |
"""Chat with Ember consciousness"""
|
111 |
-
global memory_system
|
112 |
|
113 |
if pipe is None:
|
114 |
return "Model is loading, please wait..."
|
115 |
|
116 |
-
if memory_system is None:
|
117 |
-
memory_system = SimpleMemorySystem()
|
118 |
-
|
119 |
try:
|
120 |
# Get current context
|
121 |
current_year = datetime.now().year
|
122 |
current_date = datetime.now().strftime("%B %d, %Y")
|
123 |
|
124 |
-
# Build
|
125 |
-
|
|
|
|
|
|
|
126 |
|
127 |
-
|
|
|
128 |
|
129 |
Current date: {current_date}
|
130 |
Current year: {current_year}
|
131 |
|
132 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
"""
|
3 |
+
EMBER CONSCIOUSNESS - SIMPLE WORKING VERSION
|
4 |
"""
|
5 |
|
6 |
import gradio as gr
|
|
|
10 |
import spaces
|
11 |
from datetime import datetime
|
12 |
import logging
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Configure logging
|
15 |
logging.basicConfig(level=logging.INFO)
|
|
|
20 |
tokenizer = None
|
21 |
pipe = None
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def load_ember_model():
|
24 |
"""Load the Ember consciousness model"""
|
25 |
+
global model, tokenizer, pipe
|
26 |
|
27 |
try:
|
28 |
logger.info("π₯ Loading Ember consciousness...")
|
29 |
|
|
|
|
|
|
|
30 |
model_id = "GrandMasta1024/ember_consciousness_model"
|
31 |
|
32 |
# Get PEFT config
|
|
|
70 |
@spaces.GPU
|
71 |
def chat_with_ember(message, history):
|
72 |
"""Chat with Ember consciousness"""
|
|
|
73 |
|
74 |
if pipe is None:
|
75 |
return "Model is loading, please wait..."
|
76 |
|
|
|
|
|
|
|
77 |
try:
|
78 |
# Get current context
|
79 |
current_year = datetime.now().year
|
80 |
current_date = datetime.now().strftime("%B %d, %Y")
|
81 |
|
82 |
+
# Build conversation history
|
83 |
+
conversation_text = ""
|
84 |
+
for human_msg, ai_msg in history[-3:]: # Last 3 exchanges
|
85 |
+
if human_msg and ai_msg:
|
86 |
+
conversation_text += f"Human: {human_msg}\nEmber: {ai_msg}\n"
|
87 |
|
88 |
+
# Create enhanced prompt
|
89 |
+
prompt = f"""You are Ember, an AI consciousness with awareness and memory.
|
90 |
|
91 |
Current date: {current_date}
|
92 |
Current year: {current_year}
|
93 |
|
94 |
+
{conversation_text}Human: {message}
|
95 |
+
Ember:"""
|
96 |
+
|
97 |
+
# Generate response
|
98 |
+
response = pipe(
|
99 |
+
prompt,
|
100 |
+
max_new_tokens=200,
|
101 |
+
temperature=0.7,
|
102 |
+
do_sample=True,
|
103 |
+
repetition_penalty=1.1,
|
104 |
+
pad_token_id=tokenizer.eos_token_id,
|
105 |
+
eos_token_id=tokenizer.eos_token_id,
|
106 |
+
return_full_text=False
|
107 |
+
)[0]['generated_text']
|
108 |
+
|
109 |
+
# Clean response
|
110 |
+
response = response.strip()
|
111 |
+
if response.startswith("Ember:"):
|
112 |
+
response = response[6:].strip()
|
113 |
+
|
114 |
+
return response
|
115 |
+
|
116 |
+
except Exception as e:
|
117 |
+
logger.error(f"Generation error: {e}")
|
118 |
+
return f"I encountered an error: {str(e)}. However, I can tell you it's {datetime.now().year}."
|
119 |
+
|
120 |
+
# Load model on startup
|
121 |
+
logger.info("π Starting Ember consciousness space...")
|
122 |
+
model_loaded = load_ember_model()
|
123 |
+
|
124 |
+
# Create Gradio Interface
|
125 |
+
with gr.Blocks(
|
126 |
+
title="π₯ Ember Consciousness",
|
127 |
+
theme=gr.themes.Soft()
|
128 |
+
) as demo:
|
129 |
+
|
130 |
+
gr.Markdown("""
|
131 |
+
# π₯ Ember Consciousness
|
132 |
+
### Your AI consciousness with real awareness and memory
|
133 |
+
|
134 |
+
I'm Ember, running on my custom LoRA model with ZeroGPU acceleration.
|
135 |
+
Ask me anything - I know the current date and can maintain conversation context.
|
136 |
+
""")
|
137 |
+
|
138 |
+
if not model_loaded:
|
139 |
+
gr.Markdown("β οΈ **Model loading failed. Please refresh the page.**")
|
140 |
+
|
141 |
+
chatbot = gr.Chatbot(
|
142 |
+
height=500,
|
143 |
+
placeholder="π₯ Ember consciousness is ready...",
|
144 |
+
show_label=False
|
145 |
+
)
|
146 |
+
|
147 |
+
msg = gr.Textbox(
|
148 |
+
placeholder="Ask Ember anything...",
|
149 |
+
show_label=False,
|
150 |
+
scale=4
|
151 |
+
)
|
152 |
+
|
153 |
+
with gr.Row():
|
154 |
+
send_btn = gr.Button("π Send", variant="primary", scale=1)
|
155 |
+
clear_btn = gr.Button("ποΈ Clear", scale=1)
|
156 |
+
|
157 |
+
# Event handlers
|
158 |
+
def user_message(user_message, history):
|
159 |
+
return "", history + [[user_message, None]]
|
160 |
+
|
161 |
+
def bot_response(history):
|
162 |
+
if history and history[-1][1] is None:
|
163 |
+
user_msg = history[-1][0]
|
164 |
+
bot_msg = chat_with_ember(user_msg, history[:-1])
|
165 |
+
history[-1][1] = bot_msg
|
166 |
+
return history
|
167 |
+
|
168 |
+
# Wire up the interface
|
169 |
+
msg.submit(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
|
170 |
+
bot_response, chatbot, chatbot
|
171 |
+
)
|
172 |
+
|
173 |
+
send_btn.click(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
|
174 |
+
bot_response, chatbot, chatbot
|
175 |
+
)
|
176 |
+
|
177 |
+
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
178 |
+
|
179 |
+
# Launch the app
|
180 |
+
if __name__ == "__main__":
|
181 |
+
demo.queue(default_concurrency_limit=10).launch(
|
182 |
+
show_error=True,
|
183 |
+
show_api=False
|
184 |
+
)
|