Spaces:
Sleeping
Sleeping
import os | |
import time | |
import gradio as gr | |
import requests | |
import json | |
import numpy as np | |
import google.generativeai as genai | |
from openai import OpenAI | |
from typing import List, Dict, Tuple | |
from sklearn.metrics.pairwise import cosine_similarity | |
from sentence_transformers import SentenceTransformer | |
# Animation CSS and HTML | |
LOADING_ANIMATION = """ | |
<style> | |
.thinking-animation { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100px; | |
} | |
.dot-flashing { | |
position: relative; | |
width: 10px; | |
height: 10px; | |
border-radius: 5px; | |
background-color: #4CAF50; | |
color: #4CAF50; | |
animation: dotFlashing 1s infinite linear alternate; | |
animation-delay: .5s; | |
} | |
.dot-flashing::before, .dot-flashing::after { | |
content: ''; | |
display: inline-block; | |
position: absolute; | |
top: 0; | |
} | |
.dot-flashing::before { | |
left: -15px; | |
width: 10px; | |
height: 10px; | |
border-radius: 5px; | |
background-color: #4CAF50; | |
color: #4CAF50; | |
animation: dotFlashing 1s infinite alternate; | |
animation-delay: 0s; | |
} | |
.dot-flashing::after { | |
left: 15px; | |
width: 10px; | |
height: 10px; | |
border-radius: 5px; | |
background-color: #4CAF50; | |
color: #4CAF50; | |
animation: dotFlashing 1s infinite alternate; | |
animation-delay: 1s; | |
} | |
@keyframes dotFlashing { | |
0% { background-color: #4CAF50; } | |
50%, 100% { background-color: rgba(76, 175, 80, 0.2); } | |
} | |
@keyframes spin { | |
0% { transform: rotate(0deg); } | |
100% { transform: rotate(360deg); } | |
} | |
.thinking-text { | |
text-align: center; | |
margin-top: 20px; | |
font-weight: bold; | |
color: #4CAF50; | |
} | |
</style> | |
<div class="thinking-animation"> | |
<div class="dot-flashing"></div> | |
<div class="thinking-text">AGI Thinking...</div> | |
</div> | |
""" | |
class AGICognitiveSystem: | |
# ... (keep previous class implementation unchanged) ... | |
def create_agi_interface(): | |
try: | |
agi = AGICognitiveSystem() | |
except ValueError as e: | |
return gr.Blocks().launch(error_message=str(e)) | |
with gr.Blocks(title="Advanced AGI System", theme=gr.themes.Soft(), css=""" | |
.cognitive-node { padding: 15px; margin: 10px; border-radius: 8px; background: #f8f9fa; } | |
.confidence-meter { height: 10px; background: #eee; border-radius: 5px; margin: 10px 0; } | |
.confidence-fill { height: 100%; border-radius: 5px; background: #4CAF50; } | |
""") as demo: | |
gr.Markdown("# 🧠 Advanced AGI Cognitive System") | |
with gr.Row(): | |
input_panel = gr.Textbox(label="Input Query", lines=3, | |
placeholder="Enter complex query...") | |
with gr.Accordion("Cognitive Controls", open=False): | |
depth = gr.Slider(1, 10, value=5, label="Reasoning Depth") | |
creativity = gr.Slider(0, 1, value=0.7, label="Creativity Level") | |
loading = gr.HTML(LOADING_ANIMATION, visible=False) | |
output_panel = gr.Markdown() | |
visualization = gr.HTML() | |
metrics = gr.DataFrame(headers=["Metric", "Value"]) | |
def toggle_loading(): | |
return gr.HTML(visible=True) | |
def process_query(query): | |
start_time = time.time() | |
result, metrics = agi.cognitive_flow(query) | |
return result, metrics | |
input_panel.submit( | |
fn=toggle_loading, | |
inputs=None, | |
outputs=loading, | |
queue=False | |
).then( | |
fn=process_query, | |
inputs=input_panel, | |
outputs=[output_panel, metrics], | |
).then( | |
lambda: gr.HTML(visible=False), | |
inputs=None, | |
outputs=loading, | |
queue=False | |
) | |
return demo | |
if __name__ == "__main__": | |
create_agi_interface().launch(server_port=7860) |