Dhruv Pawar
commited on
Commit
·
5c8f91b
1
Parent(s):
74ac60c
working on ui
Browse files- src/ui/modern_interface.py +0 -310
src/ui/modern_interface.py
DELETED
|
@@ -1,310 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Modern UI with all features - Compact & High Quality
|
| 3 |
-
"""
|
| 4 |
-
import gradio as gr
|
| 5 |
-
from src.core.reasoner import AdvancedReasoner
|
| 6 |
-
from src.config.constants import ReasoningMode, ModelConfig
|
| 7 |
-
from src.config.settings import AppConfig
|
| 8 |
-
from src.ui.handlers import EventHandlers
|
| 9 |
-
from src.ui.components import UIComponents
|
| 10 |
-
|
| 11 |
-
# Compact Modern CSS
|
| 12 |
-
MODERN_CSS = """
|
| 13 |
-
<style>
|
| 14 |
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
| 15 |
-
:root{--primary:#6366f1;--bg:#0f172a;--surface:rgba(255,255,255,0.05);--border:rgba(255,255,255,0.1);--text:#f1f5f9;--glow:0 0 20px rgba(99,102,241,0.3)}
|
| 16 |
-
*{font-family:'Inter',sans-serif}
|
| 17 |
-
body{background:linear-gradient(135deg,#0f172a 0%,#1e293b 100%);color:var(--text)}
|
| 18 |
-
.hero-header{background:linear-gradient(135deg,rgba(99,102,241,0.2),rgba(139,92,246,0.2));backdrop-filter:blur(20px);border:1px solid var(--border);border-radius:16px;padding:2rem;margin-bottom:1.5rem;box-shadow:var(--glow);animation:slideIn 0.5s ease}
|
| 19 |
-
.hero-header h1{font-size:2rem;font-weight:700;background:linear-gradient(135deg,#f1f5f9,#a5b4fc);-webkit-background-clip:text;-webkit-text-fill-color:transparent;margin:0 0 0.5rem}
|
| 20 |
-
.badges{display:flex;flex-wrap:wrap;gap:0.5rem;margin-top:1rem}
|
| 21 |
-
.badge{padding:0.4rem 0.8rem;background:var(--surface);border:1px solid var(--border);border-radius:8px;font-size:0.8rem;transition:all 0.3s}
|
| 22 |
-
.badge:hover{background:rgba(99,102,241,0.1);border-color:var(--primary);transform:translateY(-2px)}
|
| 23 |
-
.metrics-card{background:linear-gradient(135deg,rgba(16,185,129,0.1),rgba(6,182,212,0.1));backdrop-filter:blur(20px);border:1px solid rgba(16,185,129,0.2);border-radius:12px;padding:1.2rem;margin-top:1rem}
|
| 24 |
-
.metric-row{display:flex;justify-content:space-between;padding:0.5rem 0;border-bottom:1px solid var(--border)}
|
| 25 |
-
.metric-row:last-child{border-bottom:none}
|
| 26 |
-
.metric-label{color:#cbd5e1;font-size:0.85rem}
|
| 27 |
-
.metric-value{font-weight:700;font-family:monospace}
|
| 28 |
-
.status-active{color:#10b981}
|
| 29 |
-
.status-idle{color:#f59e0b}
|
| 30 |
-
@keyframes slideIn{from{opacity:0;transform:translateY(-20px)}to{opacity:1;transform:translateY(0)}}
|
| 31 |
-
.gradio-button{border-radius:8px;font-weight:600;transition:all 0.3s}
|
| 32 |
-
.gradio-button:hover{transform:translateY(-2px)}
|
| 33 |
-
</style>
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
# Compact Header
|
| 37 |
-
HEADER = f"""
|
| 38 |
-
<div class="hero-header">
|
| 39 |
-
<h1>🧠 AI Reasoning System Pro</h1>
|
| 40 |
-
<p style="color:#cbd5e1;margin:0">Advanced reasoning with Tree of Thoughts, Constitutional AI & Real-time Analytics</p>
|
| 41 |
-
<div class="badges">
|
| 42 |
-
<div class="badge">🌳 Tree of Thoughts</div>
|
| 43 |
-
<div class="badge">🛡️ Constitutional AI</div>
|
| 44 |
-
<div class="badge">🔬 {len(ReasoningMode)} Modes</div>
|
| 45 |
-
<div class="badge">⚡ Real-Time</div>
|
| 46 |
-
<div class="badge">💾 Smart Cache</div>
|
| 47 |
-
<div class="badge">📊 Analytics</div>
|
| 48 |
-
</div>
|
| 49 |
-
</div>
|
| 50 |
-
"""
|
| 51 |
-
|
| 52 |
-
def create_metrics_html(reasoner):
|
| 53 |
-
"""Compact metrics display"""
|
| 54 |
-
m = reasoner.metrics
|
| 55 |
-
cache = reasoner.cache.get_stats()
|
| 56 |
-
status = "status-active" if m.tokens_used > 0 else "status-idle"
|
| 57 |
-
return f"""
|
| 58 |
-
<div class="metrics-card">
|
| 59 |
-
<div class="metric-row"><span class="metric-label">⚡ Inference</span><span class="metric-value">{m.inference_time:.2f}s</span></div>
|
| 60 |
-
<div class="metric-row"><span class="metric-label">🚀 Speed</span><span class="metric-value">{m.tokens_per_second:.1f} tok/s</span></div>
|
| 61 |
-
<div class="metric-row"><span class="metric-label">🧠 Depth</span><span class="metric-value">{m.reasoning_depth} steps</span></div>
|
| 62 |
-
<div class="metric-row"><span class="metric-label">💬 Total</span><span class="metric-value">{m.total_conversations}</span></div>
|
| 63 |
-
<div class="metric-row"><span class="metric-label">📊 Tokens</span><span class="metric-value">{m.tokens_used:,}</span></div>
|
| 64 |
-
<div class="metric-row"><span class="metric-label">💾 Cache</span><span class="metric-value">{cache['hit_rate']}%</span></div>
|
| 65 |
-
<div class="metric-row"><span class="metric-label">📡 Status</span><span class="metric-value {status}">{"Active" if m.tokens_used > 0 else "Ready"}</span></div>
|
| 66 |
-
</div>
|
| 67 |
-
"""
|
| 68 |
-
|
| 69 |
-
def create_modern_ui():
|
| 70 |
-
"""Create modern UI with all features"""
|
| 71 |
-
reasoner = AdvancedReasoner()
|
| 72 |
-
components = UIComponents()
|
| 73 |
-
handlers = EventHandlers(reasoner)
|
| 74 |
-
|
| 75 |
-
with gr.Blocks(
|
| 76 |
-
theme=gr.themes.Soft(
|
| 77 |
-
primary_hue=AppConfig.THEME_PRIMARY,
|
| 78 |
-
secondary_hue=AppConfig.THEME_SECONDARY,
|
| 79 |
-
font=gr.themes.GoogleFont("Inter")
|
| 80 |
-
),
|
| 81 |
-
css=MODERN_CSS,
|
| 82 |
-
title="🧠 AI Reasoning System Pro"
|
| 83 |
-
) as demo:
|
| 84 |
-
|
| 85 |
-
gr.HTML(HEADER)
|
| 86 |
-
|
| 87 |
-
# Main Tabs
|
| 88 |
-
with gr.Tabs() as tabs:
|
| 89 |
-
|
| 90 |
-
# TAB 1: Reasoning Workspace
|
| 91 |
-
with gr.Tab("💬 Reasoning Workspace"):
|
| 92 |
-
with gr.Row():
|
| 93 |
-
with gr.Column(scale=4):
|
| 94 |
-
chatbot = gr.Chatbot(
|
| 95 |
-
label="💬 Reasoning Workspace",
|
| 96 |
-
height=600,
|
| 97 |
-
show_copy_button=True,
|
| 98 |
-
type="messages",
|
| 99 |
-
bubble_full_width=False,
|
| 100 |
-
avatar_images=(
|
| 101 |
-
"https://api.dicebear.com/7.x/avataaars/svg?seed=User&backgroundColor=6366f1",
|
| 102 |
-
"https://api.dicebear.com/7.x/bottts/svg?seed=AI&backgroundColor=8b5cf6"
|
| 103 |
-
)
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
msg = gr.Textbox(
|
| 107 |
-
placeholder="💭 Ask me anything... I'll use advanced reasoning to solve complex problems.",
|
| 108 |
-
label="Query Input",
|
| 109 |
-
lines=3,
|
| 110 |
-
max_lines=10,
|
| 111 |
-
show_label=False
|
| 112 |
-
)
|
| 113 |
-
|
| 114 |
-
with gr.Row():
|
| 115 |
-
submit_btn = gr.Button("🚀 Process", variant="primary", scale=2, size="lg")
|
| 116 |
-
clear_btn = gr.Button("🗑️ Clear", scale=1, size="lg")
|
| 117 |
-
pdf_btn = gr.Button("📄 PDF", scale=1, size="lg", variant="secondary")
|
| 118 |
-
toggle_sidebar_btn = gr.Button("⚙️ Settings", scale=1, size="lg", variant="secondary")
|
| 119 |
-
|
| 120 |
-
# Collapsible Sidebar
|
| 121 |
-
with gr.Column(scale=1, visible=True) as sidebar:
|
| 122 |
-
gr.Markdown("### ⚙️ Configuration")
|
| 123 |
-
|
| 124 |
-
reasoning_mode = gr.Radio(
|
| 125 |
-
choices=components.get_reasoning_mode_choices(),
|
| 126 |
-
value=ReasoningMode.TREE_OF_THOUGHTS.value,
|
| 127 |
-
label="🧠 Reasoning Method",
|
| 128 |
-
info="Select reasoning strategy"
|
| 129 |
-
)
|
| 130 |
-
|
| 131 |
-
prompt_template = gr.Dropdown(
|
| 132 |
-
choices=components.get_prompt_template_choices(),
|
| 133 |
-
value="Custom",
|
| 134 |
-
label="📝 Prompt Template",
|
| 135 |
-
info="Pre-built templates"
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
enable_critique = gr.Checkbox(
|
| 139 |
-
label="🔍 Enable Self-Critique",
|
| 140 |
-
value=True,
|
| 141 |
-
info="Auto validation"
|
| 142 |
-
)
|
| 143 |
-
|
| 144 |
-
use_cache = gr.Checkbox(
|
| 145 |
-
label="💾 Use Cache",
|
| 146 |
-
value=True,
|
| 147 |
-
info="Faster responses"
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
model = gr.Dropdown(
|
| 151 |
-
choices=components.get_model_choices(),
|
| 152 |
-
value=ModelConfig.LLAMA_70B.model_id,
|
| 153 |
-
label="🤖 AI Model"
|
| 154 |
-
)
|
| 155 |
-
|
| 156 |
-
with gr.Accordion("🎛️ Advanced", open=False):
|
| 157 |
-
temperature = gr.Slider(
|
| 158 |
-
AppConfig.MIN_TEMPERATURE,
|
| 159 |
-
AppConfig.MAX_TEMPERATURE,
|
| 160 |
-
value=AppConfig.DEFAULT_TEMPERATURE,
|
| 161 |
-
step=0.1,
|
| 162 |
-
label="🌡️ Temperature"
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
max_tokens = gr.Slider(
|
| 166 |
-
AppConfig.MIN_TOKENS,
|
| 167 |
-
8000,
|
| 168 |
-
value=AppConfig.DEFAULT_MAX_TOKENS,
|
| 169 |
-
step=500,
|
| 170 |
-
label="📊 Max Tokens"
|
| 171 |
-
)
|
| 172 |
-
|
| 173 |
-
gr.Markdown("### 📊 Live Metrics")
|
| 174 |
-
metrics_display = gr.HTML(value=create_metrics_html(reasoner))
|
| 175 |
-
|
| 176 |
-
with gr.Accordion("ℹ️ System Info", open=False):
|
| 177 |
-
gr.HTML(components.get_system_info_html(reasoner))
|
| 178 |
-
|
| 179 |
-
pdf_file_output = gr.File(label="📥 Download PDF", visible=True, file_types=[".pdf"])
|
| 180 |
-
sidebar_visible_state = gr.State(value=True)
|
| 181 |
-
|
| 182 |
-
# TAB 2: Export & History
|
| 183 |
-
with gr.Tab("📤 Export & History"):
|
| 184 |
-
gr.Markdown("### 📤 Export Conversations")
|
| 185 |
-
gr.Markdown("Export your conversations in multiple formats with optional metadata.")
|
| 186 |
-
|
| 187 |
-
with gr.Row():
|
| 188 |
-
export_format = gr.Radio(
|
| 189 |
-
choices=["json", "markdown", "txt", "pdf"],
|
| 190 |
-
value="markdown",
|
| 191 |
-
label="Export Format"
|
| 192 |
-
)
|
| 193 |
-
include_meta = gr.Checkbox(
|
| 194 |
-
label="Include Metadata",
|
| 195 |
-
value=True,
|
| 196 |
-
info="Timestamps, models, metrics"
|
| 197 |
-
)
|
| 198 |
-
|
| 199 |
-
export_btn = gr.Button("📥 Export Now", variant="primary", size="lg")
|
| 200 |
-
export_output = gr.Code(label="Preview", language="markdown", lines=15)
|
| 201 |
-
download_file = gr.File(label="📥 Download File", file_types=[".json", ".md", ".txt", ".pdf"])
|
| 202 |
-
|
| 203 |
-
gr.Markdown("---")
|
| 204 |
-
gr.Markdown("### 🔍 Search Conversations")
|
| 205 |
-
|
| 206 |
-
with gr.Row():
|
| 207 |
-
search_input = gr.Textbox(
|
| 208 |
-
placeholder="Enter keyword to search...",
|
| 209 |
-
scale=3,
|
| 210 |
-
label="Search Query",
|
| 211 |
-
show_label=False
|
| 212 |
-
)
|
| 213 |
-
search_btn = gr.Button("🔍 Search", scale=1, size="lg")
|
| 214 |
-
|
| 215 |
-
search_results = gr.Markdown("💡 **Tip:** Enter a keyword and click Search.")
|
| 216 |
-
|
| 217 |
-
gr.Markdown("---")
|
| 218 |
-
gr.Markdown("### 📊 Conversation History")
|
| 219 |
-
history_stats = gr.Markdown("Loading statistics...")
|
| 220 |
-
|
| 221 |
-
# TAB 3: Analytics
|
| 222 |
-
with gr.Tab("📊 Analytics & Insights"):
|
| 223 |
-
gr.Markdown("### 📊 Performance Analytics Dashboard")
|
| 224 |
-
refresh_btn = gr.Button("🔄 Refresh Analytics", variant="primary", size="lg")
|
| 225 |
-
|
| 226 |
-
with gr.Row():
|
| 227 |
-
with gr.Column():
|
| 228 |
-
gr.Markdown("#### ⚡ Performance Metrics")
|
| 229 |
-
analytics_display = gr.HTML(components.get_empty_analytics_html())
|
| 230 |
-
|
| 231 |
-
with gr.Column():
|
| 232 |
-
gr.Markdown("#### 💾 Cache Statistics")
|
| 233 |
-
cache_display = gr.Markdown("No cache data yet. Start a conversation to see cache performance.")
|
| 234 |
-
|
| 235 |
-
gr.Markdown("---")
|
| 236 |
-
gr.Markdown("### 📈 Usage Distribution")
|
| 237 |
-
|
| 238 |
-
with gr.Row():
|
| 239 |
-
with gr.Column():
|
| 240 |
-
gr.Markdown("#### 🤖 Model Usage")
|
| 241 |
-
model_dist = gr.Markdown("No data yet. Models will be tracked as you use them.")
|
| 242 |
-
|
| 243 |
-
with gr.Column():
|
| 244 |
-
gr.Markdown("#### 🧠 Reasoning Mode Usage")
|
| 245 |
-
mode_dist = gr.Markdown("No data yet. Reasoning modes will be tracked as you use them.")
|
| 246 |
-
|
| 247 |
-
# TAB 4: Settings
|
| 248 |
-
with gr.Tab("⚙️ Settings"):
|
| 249 |
-
gr.Markdown("### ⚙️ Application Settings")
|
| 250 |
-
gr.Markdown("Current configuration and system controls.")
|
| 251 |
-
gr.HTML(components.get_settings_table_html())
|
| 252 |
-
|
| 253 |
-
gr.Markdown("---")
|
| 254 |
-
gr.Markdown("### 🔧 System Actions")
|
| 255 |
-
|
| 256 |
-
with gr.Row():
|
| 257 |
-
clear_cache_btn = gr.Button("🗑️ Clear Cache", variant="stop", size="lg")
|
| 258 |
-
reset_metrics_btn = gr.Button("🔄 Reset Metrics", variant="secondary", size="lg")
|
| 259 |
-
|
| 260 |
-
cache_status = gr.Markdown("")
|
| 261 |
-
|
| 262 |
-
# Event Handlers
|
| 263 |
-
def toggle_sidebar(visible):
|
| 264 |
-
return gr.update(visible=not visible), not visible
|
| 265 |
-
|
| 266 |
-
# Reasoning workspace handlers
|
| 267 |
-
submit_btn.click(
|
| 268 |
-
handlers.process_message,
|
| 269 |
-
[msg, chatbot, reasoning_mode, enable_critique, model, temperature, max_tokens, prompt_template, use_cache],
|
| 270 |
-
[chatbot, metrics_display]
|
| 271 |
-
).then(lambda: "", None, msg)
|
| 272 |
-
|
| 273 |
-
msg.submit(
|
| 274 |
-
handlers.process_message,
|
| 275 |
-
[msg, chatbot, reasoning_mode, enable_critique, model, temperature, max_tokens, prompt_template, use_cache],
|
| 276 |
-
[chatbot, metrics_display]
|
| 277 |
-
).then(lambda: "", None, msg)
|
| 278 |
-
|
| 279 |
-
clear_btn.click(handlers.reset_chat, None, [chatbot, metrics_display])
|
| 280 |
-
pdf_btn.click(handlers.download_chat_pdf, None, pdf_file_output)
|
| 281 |
-
toggle_sidebar_btn.click(toggle_sidebar, sidebar_visible_state, [sidebar, sidebar_visible_state])
|
| 282 |
-
|
| 283 |
-
# Export handlers (corrected method name)
|
| 284 |
-
export_btn.click(
|
| 285 |
-
handlers.export_conversation,
|
| 286 |
-
[export_format, include_meta],
|
| 287 |
-
[export_output, download_file]
|
| 288 |
-
)
|
| 289 |
-
|
| 290 |
-
search_btn.click(
|
| 291 |
-
handlers.search_conversations,
|
| 292 |
-
search_input,
|
| 293 |
-
search_results
|
| 294 |
-
)
|
| 295 |
-
|
| 296 |
-
# Analytics handlers
|
| 297 |
-
refresh_btn.click(
|
| 298 |
-
handlers.refresh_analytics,
|
| 299 |
-
None,
|
| 300 |
-
[analytics_display, cache_display, model_dist, mode_dist]
|
| 301 |
-
)
|
| 302 |
-
|
| 303 |
-
# Settings handlers
|
| 304 |
-
clear_cache_btn.click(handlers.clear_cache_action, None, cache_status)
|
| 305 |
-
reset_metrics_btn.click(handlers.reset_metrics_action, None, cache_status)
|
| 306 |
-
|
| 307 |
-
# Load initial data
|
| 308 |
-
demo.load(handlers.update_history_stats, None, history_stats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