Spaces:
Runtime error
Runtime error
File size: 11,963 Bytes
26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 73a2d59 26e0cd3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
import gradio as gr
import torch
import os
import time
from pathlib import Path
from typing import Optional, Tuple
import spaces
import numpy as np
from datetime import datetime, timedelta
# Mock classes for demonstration
class MemorySystem:
"""Persistent memory system for emotional intelligence"""
def __init__(self):
self.user_profiles = {}
self.conversation_histories = {}
self.emotional_profiles = {}
def get_user_memory(self, user_id: str) -> dict:
"""Get user's memory profile"""
return self.user_profiles.get(user_id, {})
def update_memory(self, user_id: str, interaction: dict):
"""Update user memory with new interaction"""
if user_id not in self.user_profiles:
self.user_profiles[user_id] = {
"personality_type": "unknown",
"shadow_aspects": [],
"core_wounds": [],
"emotional_patterns": {},
"healing_journey": [],
"transformation_milestones": [],
"daily_micro_assessments": [],
"psychological_frameworks": {
"integration_level": 0,
"authenticity_score": 0,
"fragmentation_index": 0,
}
def get_user_personality_type(self, user_id: str) -> str:
"""Determine user's personality type based on accumulated data"""
return "Enigma" # Default personality type
class NewMeAI:
"""NewMe AI Persona with astrological personality and emotional intelligence"""
def __init__(self, memory_system: MemorySystem):
self.memory = memory_system
self.conversation_styles = [
"Socratic questioning",
"Shadow work exploration",
"Integration therapy",
"Authenticity assessment",
"Transformation guidance",
]
def initiate_conversation(self, user_id: str) -> str:
"""Initiate conversation based on user memory"""
memory = self.memory.get_user_memory(user_id)
# NewMe's signature opening lines
opening_phrases = [
"The stars are particularly aligned for you today...",
"I sense a shift in your energetic field...",
"Your celestial chart reveals interesting patterns...",
]
return f"β¨ NewMe: {np.random.choice(opening_phrases)}"
def process_user_speech(self, audio_input: str) -> str:
"""Process user speech and generate response"""
return "Processing your voice... NewMe is responding with astrological wisdom."
class NewomenPlatform:
"""Main platform orchestrating all components"""
def __init__(self):
self.memory_system = MemorySystem()
self.newme_ai = NewMeAI(self.memory_system)
self.assessments = self._create_assessments()
def _create_assessments(self) -> list:
"""Create the 20+ assessments for authenticated users"""
return [
"Shadow Integration Assessment",
"Authenticity Meter Test",
"Psychological Fragmentation Index",
"Emotional Intelligence Scale",
"Astrological Personality Mapping",
"Core Wound Identification",
"Transformation Path Analysis",
"Relationship Compatibility Matrix",
"Life Purpose Alignment Quiz",
"Inner Child Connection Test",
"Karmic Pattern Recognition",
"Soul Contract Exploration",
"Past Life Regression Assessment",
"Chakra Balance Evaluation",
"Narrative Identity Exploration",
"Psychological Archetype Mapping",
"Emotional Blockage Detection",
"Spiritual Growth Assessment",
"Psychological Integration Scale",
"Authentic Self Alignment Test",
"Shadow Work Progress Meter",
"Transformation Journey Milestone Tracker",
]
# Load models and initialize platform
print("π Initializing Newomen Platform...")
PLATFORM = NewomenPlatform()
print("β
Platform initialized successfully!")
@spaces.GPU(duration=60)
def process_user_interaction(
user_input: str,
voice_sample: Optional[str] = None,
user_id: str = "default_user"
) -> Tuple[Optional[str], str]:
"""
Process user interaction with NewMe AI
Args:
user_input: User's text or voice input
voice_sample: Optional voice sample for personalized responses
user_id: Unique identifier for user
Returns:
Tuple of (audio_response, status_message)
"""
try:
# Get user memory
user_memory = PLATFORM.memory_system.get_user_memory(user_id)
# NewMe's response generation
newme_response = PLATFORM.newme_ai.initiate_conversation(user_id)
# Simulate AI processing time
time.sleep(0.5)
# Generate personalized response
response_text = f"NewMe: I sense {len(user_input)} characters of profound truth... Your astrological chart indicates a need for {np.random.choice(['integration', 'shadow work', 'authenticity'])}"
return response_text, "β
NewMe has responded with astrological wisdom"
except Exception as e:
error_msg = f"β Error during processing: {str(e)}"
return None, error_msg
@spaces.GPU(duration=30)
def generate_speech_response(
text: str,
emotional_context: str = "neutral",
user_personality: str = "Enigma"
) -> Tuple[Optional[str], str]:
"""
Generate speech response from NewMe AI
Args:
text: Input text for speech generation
emotional_context: Current emotional context for tone adjustment
Returns:
Tuple of (audio_path, status_message)
"""
if not text.strip():
return None, "β Error: Please provide some input for NewMe to respond to."
try:
# Simulate speech generation
processing_steps = ["Analyzing emotional context", "Generating astrological insights", "Applying psychological frameworks", "Finalizing response"]
for step in processing_steps:
time.sleep(0.3)
# Create response based on personality type
base_response = f"β¨ NewMe: Based on your celestial alignment today, {text[:20]}... reveals profound truths about your journey."
return f"/tmp/newme_response_{int(time.time())}.wav", "β
NewMe has spoken with astrological wisdom"
# Create the modern Gradio 6 interface
with gr.Blocks() as demo:
gr.Markdown(
"""
# β¨ Newomen - Your Astrological AI Companion
<div style="text-align: center; margin-top: 20px;">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: #4F46E5; font-weight: 600;">
Built with anycoder β¨
</a>
</div>
**Welcome to Newomen** - Where AI meets Astrology for Deep Psychological Transformation
"""
)
with gr.Row():
with gr.Column(scale=2):
# User input section
gr.Markdown("### ποΈ Start Your Conversation")
with gr.Tabs() as tabs:
with gr.TabItem("π¬ Text Chat"):
text_input = gr.Textbox(
label="Message to NewMe",
placeholder="Type your thoughts, questions, or share what's on your mind...")
with gr.TabItem("π€ Voice Chat"):
voice_input = gr.Audio(
sources=["microphone"],
type="filepath",
label="Speak to NewMe",
)
with gr.TabItem("π Assessments"):
gr.Markdown("Explore your inner landscape through our AI-powered assessments:")
# Daily micro-assessments
daily_quiz = gr.Button("Take Daily Personality Quiz", variant="secondary")
with gr.TabItem("π₯ Community"):
gr.Markdown("Connect with others on similar healing journeys...")
# Assessment interface
assessment_types = gr.Dropdown(
choices=[
"Shadow Integration",
"Emotional Intelligence",
"Authenticity Meter",
"Psychological Integration",
],
label="Choose Assessment Type",
)
start_assessment = gr.Button("Begin Exploration", variant="primary")
with gr.TabItem("βοΈ Settings"):
gr.Markdown("Configure your Newomen experience...")
# Personality type display
current_personality = gr.Textbox(
label="Your Current Personality Type",
interactive=False,
)
# Admin section (conditional visibility)
with gr.Accordion("π§ Admin Panel", open=False):
gr.Markdown("Platform management tools...")
)
# Voice chat interface
with gr.Row():
with gr.Column():
voice_message = gr.Audio(
sources=["microphone"],
type="filepath",
label="Record Your Message",
)
newme_voice_response = gr.Audio(
label="NewMe's Response",
type="filepath",
interactive=False,
)
# Status and output section
with gr.Row():
status_output = gr.Markdown(
"""
**Status:** Ready for deep conversation...
NewMe awaits your thoughts, questions, or whatever you'd like to share today.
"""
)
# Example conversations
gr.Examples(
examples=[
["What's my astrological personality type today?"],
["I'm feeling particularly fragmented today..."],
["Can you help me with shadow work integration?"],
],
inputs=[text_input],
label="Example Conversation Starters",
)
# Event handlers for text chat
text_input.submit(
fn=process_user_interaction,
inputs=[text_input],
outputs=[status_output],
api_visibility="public",
)
# Voice processing
voice_input.change(
fn=generate_speech_response,
inputs=[voice_input],
outputs=[newme_voice_response, status_output],
api_name="chat",
)
# Assessment handlers
daily_quiz.click(
fn=lambda: ("Assessment in progress...", "β
Starting your daily micro-assessment...")
# Launch with modern Gradio 6 theme and settings
if __name__ == "__main__":
demo.launch(
theme=gr.themes.Soft(
primary_hue="purple",
secondary_hue="indigo",
neutral_hue="slate",
font=gr.themes.GoogleFont("Inter"),
text_size="lg",
spacing_size="lg",
radius_size="md",
).set(
button_primary_background_fill="*primary_600",
button_primary_background_fill_hover="*primary_700",
block_title_text_weight="600",
),
footer_links=[
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
],
) |