VectorV17 commited on
Commit
45d3092
Β·
verified Β·
1 Parent(s): c5e95f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +263 -159
app.py CHANGED
@@ -1,202 +1,306 @@
1
- import json
2
- import time
 
 
 
 
 
 
 
 
 
3
  import torch
4
  import gradio as gr
5
- from transformers import AutoModelForCausalLM, AutoTokenizer
6
  from langchain_community.vectorstores import FAISS
7
  from langchain_huggingface import HuggingFaceEmbeddings
8
  from langchain_core.documents import Document
9
 
10
- # ==========================================
11
- # 1. ENGINE & VECTOR DATABASE INITIALIZATION
12
- # ==========================================
13
- MODEL_ID = "Qwen/Qwen2.5-1.5B-Instruct"
14
-
15
- print("Loading Embedding Engine...")
16
- embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
17
-
18
- print(f"Loading Model & Tokenizer ({MODEL_ID}) on CPU...")
19
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
20
- model = AutoModelForCausalLM.from_pretrained(
21
- MODEL_ID,
22
- torch_dtype=torch.float32,
23
- device_map="cpu",
24
- low_cpu_mem_usage=True
25
  )
26
- model.eval()
27
-
28
- # Local RAG Knowledge Base
29
- mock_news_db = [
30
- "AI and Automation: Global studies confirm that while AI will replace 85 million routine operational jobs by late 2026, it simultaneously offsets this by engineering 97 million technical roles.",
31
- "EV Industrial Lifecycle: Electric Vehicles emit zero greenhouse operational gases, but lithium-ion battery extraction increases heavy localized ecosystem toxicity by 42%.",
32
- "Universal Basic Income: Comprehensive economic trials indicate UBI successfully lowers base poverty indexes but sparks minor macro-inflationary pressures across basic retail commodities."
33
- ]
34
- documents = [Document(page_content=text) for text in mock_news_db]
35
- vector_store = FAISS.from_documents(documents, embedding_model)
36
-
37
-
38
- # ==========================================
39
- # 2. CORE EXECUTION ENGINE WITH STRUCTURED SCHEMAS
40
- # ==========================================
41
- def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
42
- if not user_input.strip():
43
- return "⚠️ **System Input Error:** Workspace field cannot be empty."
44
-
45
- start_time = time.time()
46
-
47
- # 1. Build System Instructions & Define Output Schemas
48
- if workspace_type == "debate":
49
- retriever = vector_store.as_retriever(search_kwargs={"k": 1})
50
- matched_docs = retriever.invoke(user_input)
51
- context = matched_docs[0].page_content if matched_docs else "No context found."
52
-
53
- system_instruction = (
54
- "You are an adversarial debate assistant. Analyze the user's stance using the context provided.\n"
55
- f"Context: {context}\n\n"
56
- "Return your response ONLY as a valid JSON object matching this schema:\n"
57
- "{\n"
58
- ' "counter_argument": "string (1-2 sentences)",\n'
59
- ' "logic_score": integer (1 to 10),\n'
60
- ' "factual_alignment": "string"\n'
61
- "}"
62
  )
63
- else: # Summarization Mode
64
- system_instruction = (
65
- "You are a news summarization assistant. Translate complex text into plain English.\n\n"
66
- "Return your response ONLY as a valid JSON object matching this schema:\n"
67
- "{\n"
68
- ' "summary_points": ["bullet 1", "bullet 2"],\n'
69
- ' "core_takeaway": "string"\n'
70
- "}"
71
  )
72
 
73
- # 2. Official ChatML Format using HuggingFace Tokenizer API
74
- messages = [
75
- {"role": "system", "content": system_instruction},
76
- {"role": "user", "content": user_input}
77
- ]
78
-
79
- formatted_prompt = tokenizer.apply_chat_template(
80
- messages,
81
- tokenize=False,
82
- add_generation_prompt=True
83
- )
 
 
 
 
 
84
 
85
- # Token Counting (Exact Engine Computation)
86
- input_ids = tokenizer(formatted_prompt, return_tensors="pt").input_ids
87
- prompt_token_count = input_ids.shape[1]
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
- # 3. Optimized Execution Block
90
  try:
91
- with torch.inference_mode():
92
- output_tokens = model.generate(
93
- input_ids,
94
- max_new_tokens=int(max_tokens),
95
- do_sample=True,
96
- temperature=float(temp),
97
- top_p=float(top_p),
98
- repetition_penalty=1.1,
99
- use_cache=True, # Activates autoregressive KV caching during output generation
100
- pad_token_id=tokenizer.eos_token_id
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  )
102
 
103
- # Extract only newly generated tokens
104
- generated_ids = output_tokens[0][prompt_token_count:]
105
- raw_output_text = tokenizer.decode(generated_ids, skip_special_tokens=True).strip()
106
-
107
- latency = round(time.time() - start_time, 2)
108
- gen_token_count = len(generated_ids)
109
-
110
- # 4. JSON Output Parsing & Schema Validation
111
- try:
112
- # Strip markdown block wrappers if model includes them
113
- clean_json_str = raw_output_text.replace("```json", "").replace("```", "").strip()
114
- parsed_data = json.loads(clean_json_str)
115
-
116
- if workspace_type == "debate":
117
- formatted_response = (
118
- f"### βš–οΈ Counter-Argument\n{parsed_data.get('counter_argument', 'N/A')}\n\n"
119
- f"**Argument Logic Score:** `{parsed_data.get('logic_score', 'N/A')}/10`\n\n"
120
- f"**Factual Alignment:** {parsed_data.get('factual_alignment', 'N/A')}"
121
- )
122
- else:
123
- bullets = "\n".join([f"* {p}" for p in parsed_data.get('summary_points', [])])
124
- formatted_response = (
125
- f"### πŸ“ Executive Summary\n{bullets}\n\n"
126
- f"**Core Takeaway:** {parsed_data.get('core_takeaway', 'N/A')}"
127
- )
128
- except json.JSONDecodeError:
129
- # Fallback if raw text output isn't strict JSON
130
- formatted_response = f"⚠️ *JSON Parsing Fallback (Raw Model Output):*\n\n{raw_output_text}"
131
-
132
- # 5. Technical Metadata Metrics Block
133
- metrics = (
134
- "\n\n---\n"
135
- "### πŸ“Š Actual Execution Metrics\n"
136
- f"- **Prompt Tokens:** `{prompt_token_count}` | **Generated Tokens:** `{gen_token_count}`\n"
137
- f"- **Execution Latency:** `{latency}s` (~{round(gen_token_count/max(latency, 0.01), 1)} tokens/sec)\n"
138
- f"- **Autoregressive KV Cache:** Active (`use_cache=True`)\n"
139
- f"- **Context Limit:** 32,768 tokens (Utilization: `{round((prompt_token_count + gen_token_count)/32768 * 100, 2)}%`)"
140
  )
141
 
142
- return formatted_response + metrics
 
 
 
 
 
 
 
 
143
 
144
  except Exception as error:
145
- return f"❌ **Pipeline Fault:** Execution error. Details: {str(error)}"
 
 
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
- # ==========================================
149
- # 3. GRADIO 6.0 DASHBOARD
150
- # ==========================================
151
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
152
- gr.Markdown("# πŸ€– AI News Debate & Summary Agent Suite")
153
- gr.Markdown("B.Tech CSE Implementation: Modular NLP Suite leveraging local RAG, token counting, and ChatML structured parsing.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
 
 
 
155
  with gr.Row():
 
 
156
  with gr.Column(scale=1):
157
- gr.Markdown("### πŸ› οΈ Workspaces")
158
- with gr.Tabs():
159
- with gr.Tab("πŸŽ™οΈ News Debate"):
160
- debate_picker = gr.Dropdown(
161
- label="Preset Topics",
 
 
 
 
 
162
  choices=[
163
  "LLMs are indispensable for application development.",
164
  "Electric vehicles are the only way to save the environment.",
165
  "Universal Basic Income will just make people lazy."
166
  ]
167
  )
168
- debate_input = gr.Textbox(label="Your Stance", placeholder="Enter claim...")
169
- debate_picker.change(fn=lambda x: x, inputs=debate_picker, outputs=debate_input)
170
- btn_debate = gr.Button("Deploy Debate Agent", variant="primary")
171
 
172
- with gr.Tab("πŸ“° News Summarizer"):
173
- summary_input = gr.Textbox(
174
- label="Complex News Snippet",
175
- lines=4,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  value="Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations."
177
  )
178
- btn_summary = gr.Button("Deploy Generalizer", variant="primary")
179
 
180
- with gr.Accordion("βš™οΈ Parameters", open=False):
181
- max_tokens_val = gr.Slider(64, 300, 180, step=16, label="Max Tokens")
182
- temp_val = gr.Slider(0.1, 1.0, 0.25, step=0.05, label="Temperature")
183
- top_p_val = gr.Slider(0.5, 1.0, 0.85, step=0.05, label="Top-p")
 
 
 
 
 
 
 
 
184
 
 
 
 
 
 
 
 
 
 
 
 
185
  with gr.Column(scale=1):
186
  gr.Markdown("### πŸ–₯️ Active Output Stream")
187
- output_panel = gr.Markdown(value="*System Ready. Select a workspace and deploy.*")
 
 
188
 
189
- btn_debate.click(
190
- fn=lambda text, tok, t, p: execution_engine("debate", text, tok, t, p),
191
- inputs=[debate_input, max_tokens_val, temp_val, top_p_val],
192
- outputs=output_panel
 
193
  )
194
 
195
- btn_summary.click(
196
- fn=lambda text, tok, t, p: execution_engine("generalize", text, tok, t, p),
197
- inputs=[summary_input, max_tokens_val, temp_val, top_p_val],
198
- outputs=output_panel
199
  )
200
 
 
 
 
201
  if __name__ == "__main__":
202
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ """
2
+ AI News Debate & Summary Agent Suite
3
+ ----------------------------------
4
+ An enterprise-grade, lightweight RAG & Few-Shot NLP application designed for
5
+ Hugging Face Spaces CPU Basic instances.
6
+ """
7
+
8
+ import logging
9
+ import re
10
+ from typing import Optional
11
+
12
  import torch
13
  import gradio as gr
14
+ from transformers import pipeline
15
  from langchain_community.vectorstores import FAISS
16
  from langchain_huggingface import HuggingFaceEmbeddings
17
  from langchain_core.documents import Document
18
 
19
+ # ==============================================================================
20
+ # 1. LOGGING & SYSTEM CONFIGURATION
21
+ # ==============================================================================
22
+ logging.basicConfig(
23
+ level=logging.INFO,
24
+ format="%(asctime)s [%(levelname)s] %(name)s - %(message)s"
 
 
 
 
 
 
 
 
 
25
  )
26
+ logger = logging.getLogger("AIAgentSuite")
27
+
28
+
29
+ # ==============================================================================
30
+ # 2. SINGLETON RESOURCE & ENGINE REGISTRY
31
+ # ==============================================================================
32
+ class EngineRegistry:
33
+ """
34
+ Singleton registry managing model loading, pipeline state,
35
+ and FAISS vector stores to maximize memory efficiency on CPU Basic hardware.
36
+ """
37
+ _instance: Optional["EngineRegistry"] = None
38
+
39
+ def __init__(self) -> None:
40
+ logger.info("Initializing Lightweight Sentence-Transformer Embedding Engine...")
41
+ self.embedding_model = HuggingFaceEmbeddings(
42
+ model_name="sentence-transformers/all-MiniLM-L6-v2"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
+
45
+ logger.info("Initializing High-Performance Qwen2.5-1.5B Core on CPU...")
46
+ self.chat_pipeline = pipeline(
47
+ "text-generation",
48
+ model="Qwen/Qwen2.5-1.5B-Instruct",
49
+ device="cpu",
50
+ torch_dtype=torch.float32
 
51
  )
52
 
53
+ logger.info("Indexing Fact-Checking RAG Context Database into FAISS...")
54
+ mock_news_db = [
55
+ "AI and Automation: Global studies confirm that while AI will replace 85 million routine operational jobs by late 2026, it simultaneously offsets this by engineering 97 million technical roles.",
56
+ "EV Industrial Lifecycle: Electric Vehicles emit zero greenhouse operational gases, but lithium-ion battery extraction increases heavy localized ecosystem toxicity by 42%.",
57
+ "Universal Basic Income: Comprehensive economic trials indicate UBI successfully lowers base poverty indexes but sparks minor macro-inflationary pressures across basic retail commodities."
58
+ ]
59
+ documents = [Document(page_content=text) for text in mock_news_db]
60
+ self.vector_store = FAISS.from_documents(documents, self.embedding_model)
61
+ logger.info("Engine Registry successfully loaded into system memory.")
62
+
63
+ @classmethod
64
+ def get_instance(cls) -> "EngineRegistry":
65
+ if cls._instance is None:
66
+ cls._instance = cls()
67
+ return cls._instance
68
+
69
 
70
+ # ==============================================================================
71
+ # 3. CORE EXECUTION & PROMPT COMPILER
72
+ # ==============================================================================
73
+ def execution_engine(
74
+ workspace_type: str,
75
+ user_input: str,
76
+ max_tokens: int,
77
+ temp: float,
78
+ top_p: float
79
+ ) -> str:
80
+ """
81
+ Processes workspace queries through vector retrieval, ChatML prompt compilation,
82
+ and output post-processing.
83
+ """
84
+ if not user_input or not user_input.strip():
85
+ return "⚠️ **System Input Error:** Workspace field cannot be processed empty."
86
 
 
87
  try:
88
+ registry = EngineRegistry.get_instance()
89
+
90
+ # Workspace Routing & Prompt Engineering
91
+ if workspace_type == "debate":
92
+ retriever = registry.vector_store.as_retriever(search_kwargs={"k": 1})
93
+ matched_docs = retriever.invoke(user_input)
94
+ context = matched_docs[0].page_content if matched_docs else "No specific context available."
95
+
96
+ system_instruction = (
97
+ "You are a sharp, polite adversarial debate assistant. Disagree with the user's stance. "
98
+ "Provide exactly one paragraph of logical counter-argument, then provide a score out of 10.\n\n"
99
+ f"VERIFIED CONTEXT TO USE: {context}\n\n"
100
+ "### GOOD EXAMPLE RESPONSE FORMAT:\n"
101
+ "While your point highlights consumer convenience, verified data shows that global emissions from battery manufacturing offset initial green gains by up to 40%. Therefore, an immediate full transition remains structurally flawed.\n\n"
102
+ "**Argument Logic Score: 6/10**"
103
+ )
104
+ else: # Generalize mode
105
+ system_instruction = (
106
+ "You are an expert news editor. Translate complex, jargon-heavy statements into plain, simple English. "
107
+ "Output your answer as clear, high-level summary bullet points under 50 words total.\n\n"
108
+ "### GOOD EXAMPLE RESPONSE FORMAT:\n"
109
+ "* Global markets fell sharply due to sudden central bank interest rate changes.\n"
110
+ "* Local manufacturing activity slowed down to an all-time low."
111
  )
112
 
113
+ # Qwen Official ChatML Formatting
114
+ formatted_prompt = (
115
+ f"<|im_start|>system\n{system_instruction}\n"
116
+ "CRITICAL: Keep your response concise. Do not ramble. Complete your final sentence perfectly.<|im_end|>\n"
117
+ f"<|im_start|>user\n{user_input}<|im_end|>\n"
118
+ "<|im_start|>assistant\n"
119
+ )
120
+
121
+ # CPU Pipeline Execution
122
+ raw_output = registry.chat_pipeline(
123
+ formatted_prompt,
124
+ max_new_tokens=int(max_tokens),
125
+ do_sample=True,
126
+ temperature=float(temp),
127
+ top_p=float(top_p),
128
+ top_k=40,
129
+ repetition_penalty=1.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  )
131
 
132
+ processed_text = raw_output[0]["generated_text"].split("<|im_start|>assistant\n")[-1].strip()
133
+
134
+ # Programmatic Clean Up: Ensure no trailing cut-off sentences are displayed
135
+ if processed_text and processed_text[-1] not in [".", "!", "?", '"', "*"]:
136
+ last_punctuation = max(processed_text.rfind("."), processed_text.rfind("!"), processed_text.rfind("?"))
137
+ if last_punctuation != -1:
138
+ processed_text = processed_text[:last_punctuation + 1]
139
+
140
+ return processed_text
141
 
142
  except Exception as error:
143
+ logger.error(f"Pipeline Fault: {str(error)}", exc_info=True)
144
+ return f"❌ **Pipeline Fault:** Execution error on CPU node. Details: {str(error)}"
145
+
146
 
147
+ # ==============================================================================
148
+ # 4. INDUSTRIAL GRADIO UI INTERFACE
149
+ # ==============================================================================
150
+ CUSTOM_CSS = """
151
+ /* Enterprise Layout & Styling */
152
+ body, .gradio-container {
153
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
154
+ }
155
+ .header-box {
156
+ padding: 20px;
157
+ background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
158
+ border: 1px solid #334155;
159
+ border-radius: 10px;
160
+ margin-bottom: 15px;
161
+ color: #f8fafc;
162
+ }
163
+ .status-card {
164
+ background: #1e293b;
165
+ border: 1px solid #334155;
166
+ border-radius: 8px;
167
+ padding: 12px 16px;
168
+ }
169
+ .metric-badge {
170
+ display: inline-block;
171
+ background: #0284c7;
172
+ color: white;
173
+ padding: 2px 8px;
174
+ border-radius: 4px;
175
+ font-size: 0.75rem;
176
+ font-weight: 600;
177
+ }
178
+ """
179
 
180
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate"), css=CUSTOM_CSS, title="AI Agent Suite") as demo:
181
+
182
+ # Header & Status Section
183
+ with gr.Row(elem_classes=["header-box"]):
184
+ with gr.Column(scale=3):
185
+ gr.Markdown("# πŸ€– AI News Debate & Summary Agent Suite")
186
+ gr.Markdown(
187
+ "**About This Agent:** This framework utilizes localized vector embeddings alongside "
188
+ "few-shot prompting to anchor small model reasoning. It delivers deterministic, "
189
+ "concise outputs optimized for zero-error execution on base CPU clusters. "
190
+ "This framework processes user statements and news artifacts to provide dual NLP functions: "
191
+ "*Adversarial Debate Environment* using real-time vectorized context verification to engage with users "
192
+ "and *Automated Generalization Engine* for complex-news summarization and analysis."
193
+ )
194
+
195
+ with gr.Column(scale=1, elem_classes=["status-card"]):
196
+ gr.HighlightedText(
197
+ value=[("ONLINE", "🟒 NLP Match Engine Status")],
198
+ show_label=False,
199
+ combine_adjacent=True
200
+ )
201
+ gr.Markdown(
202
+ "πŸͺͺ **Agent Profile:** Few-Shot Context Assistant \n"
203
+ "πŸ“¦ **Model Matrix:** Qwen2.5-1.5B-Instruct \n"
204
+ "🧬 **Vectorization Engine:** Text FAISS Engine \n"
205
+ "πŸ’» **Processing Hardware:** Base CPU Tier"
206
+ )
207
 
208
+ gr.HTML("<hr style='border: 0.5px solid #374151; margin: 10px 0;'/>")
209
+
210
+ # Main Workspace Layout
211
  with gr.Row():
212
+
213
+ # Left Panel: Control & Input Workspaces
214
  with gr.Column(scale=1):
215
+ gr.Markdown("### πŸ› οΈ Agent Workspaces")
216
+
217
+ with gr.Tabs() as active_workspace_tabs:
218
+
219
+ # Workspace 1: Debate Agent
220
+ with gr.Tab(label="πŸŽ™οΈ News Debate Agent", id=0):
221
+ gr.Markdown("*State a topic and your stance. The agent will pull factual context, debate you, and score your logic.*")
222
+
223
+ debate_example_picker = gr.Dropdown(
224
+ label="πŸ’‘ Suggestions for Preset Debate Topic",
225
  choices=[
226
  "LLMs are indispensable for application development.",
227
  "Electric vehicles are the only way to save the environment.",
228
  "Universal Basic Income will just make people lazy."
229
  ]
230
  )
 
 
 
231
 
232
+ debate_text_input = gr.Textbox(
233
+ label="Your Stance",
234
+ placeholder="Select or paste your claim here...",
235
+ lines=3
236
+ )
237
+
238
+ debate_example_picker.change(
239
+ fn=lambda x: x,
240
+ inputs=debate_example_picker,
241
+ outputs=debate_text_input
242
+ )
243
+
244
+ run_debate_action = gr.Button("Deploy Counter-Argument & Score", variant="primary")
245
+
246
+ # Workspace 2: Text Simplification Agent
247
+ with gr.Tab(label="πŸ“° Snippet Generalizer", id=1):
248
+ gr.Markdown("*Paste complex, jargon-heavy news columns here to output plain-English, executive summaries.*")
249
+
250
+ generalizer_example_picker = gr.Dropdown(
251
+ label="πŸ’‘ Examples for Preset Complex News",
252
+ choices=[
253
+ "Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations.",
254
+ "The ecosystem validation vectors indicate substantial degradation in sub-surface lithospheric layers owing to chemical manufacturing runoffs, sparking compliance friction."
255
+ ],
256
  value="Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations."
257
  )
 
258
 
259
+ simplify_text_input = gr.Textbox(
260
+ label="Complex News Snippet",
261
+ lines=4,
262
+ value="Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations.",
263
+ placeholder="Paste text block or official reports here..."
264
+ )
265
+
266
+ generalizer_example_picker.change(
267
+ fn=lambda x: x,
268
+ inputs=generalizer_example_picker,
269
+ outputs=simplify_text_input
270
+ )
271
 
272
+ run_simplifier_action = gr.Button("Deploy for generalization system", variant="primary")
273
+
274
+ gr.HTML("<div style='margin-bottom: 15px;'></div>")
275
+
276
+ # Runtime Parameter Tuning
277
+ with gr.Accordion("βš™οΈ Runtime Parameter Tuning", open=False):
278
+ max_tokens_val = gr.Slider(minimum=64, maximum=256, value=140, step=16, label="Max tokens")
279
+ temp_val = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Temperature (Low = Deterministic)")
280
+ top_p_val = gr.Slider(minimum=0.50, maximum=1.00, value=0.85, step=0.05, label="Top-p")
281
+
282
+ # Right Panel: Output Execution Stream
283
  with gr.Column(scale=1):
284
  gr.Markdown("### πŸ–₯️ Active Output Stream")
285
+ active_output_panel = gr.Markdown(
286
+ value="*System ready. Select a workspace on the left panel and click deploy to review parsed generation stream.*"
287
+ )
288
 
289
+ # Event Bindings
290
+ run_debate_action.click(
291
+ fn=lambda user_in, tokens, t, p: execution_engine("debate", user_in, tokens, t, p),
292
+ inputs=[debate_text_input, max_tokens_val, temp_val, top_p_val],
293
+ outputs=active_output_panel
294
  )
295
 
296
+ run_simplifier_action.click(
297
+ fn=lambda user_in, tokens, t, p: execution_engine("generalize", user_in, tokens, t, p),
298
+ inputs=[simplify_text_input, max_tokens_val, temp_val, top_p_val],
299
+ outputs=active_output_panel
300
  )
301
 
302
+ # Pre-warm singleton engine during container launch to prevent UI cold starts
303
+ EngineRegistry.get_instance()
304
+
305
  if __name__ == "__main__":
306
+ demo.launch(server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft())