Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,157 +1,329 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import logging
|
| 3 |
-
import numpy as np
|
| 4 |
-
import torch
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
from transformers import pipeline
|
| 7 |
-
from
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# ==========================================
|
| 10 |
-
# 1.
|
| 11 |
# ==========================================
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
"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.",
|
| 21 |
"EV Industrial Lifecycle: Electric Vehicles emit zero greenhouse operational gases, but lithium-ion battery extraction increases heavy localized ecosystem toxicity by 42%.",
|
| 22 |
"Universal Basic Income: Comprehensive economic trials indicate UBI successfully lowers base poverty indexes but sparks minor macro-inflationary pressures across basic retail commodities."
|
| 23 |
]
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
# Pre-compute document embeddings normalized for Cosine Similarity
|
| 26 |
-
doc_embeddings = embedder.encode(MOCK_NEWS_DB, normalize_embeddings=True)
|
| 27 |
-
|
| 28 |
-
def retrieve_context(query: str, similarity_threshold: float = 0.35):
|
| 29 |
-
"""Pure NumPy Cosine Similarity Vector Retrieval (No LangChain needed)."""
|
| 30 |
-
query_emb = embedder.encode([query], normalize_embeddings=True)
|
| 31 |
-
scores = np.dot(doc_embeddings, query_emb.T).flatten() # Dot product of normalized vectors = Cosine Similarity
|
| 32 |
-
best_idx = int(np.argmax(scores))
|
| 33 |
-
|
| 34 |
-
if scores[best_idx] >= similarity_threshold:
|
| 35 |
-
return MOCK_NEWS_DB[best_idx], float(scores[best_idx])
|
| 36 |
-
return "No verified context matched.", float(scores[best_idx])
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
logger.info("Loading Qwen2.5-1.5B Instruct Pipeline...")
|
| 40 |
-
chat_pipeline = pipeline(
|
| 41 |
-
"text-generation",
|
| 42 |
-
model="Qwen/Qwen2.5-1.5B-Instruct",
|
| 43 |
-
device="cpu",
|
| 44 |
-
torch_dtype=torch.float32
|
| 45 |
-
)
|
| 46 |
|
| 47 |
# ==========================================
|
| 48 |
-
# 2.
|
| 49 |
# ==========================================
|
| 50 |
-
def execution_engine(workspace_type
|
| 51 |
-
if not user_input
|
| 52 |
-
return "โ ๏ธ **System Error:**
|
| 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 |
-
user_input = tokenizer.decode(truncated_ids)
|
| 85 |
-
logger.warning("User input truncated to satisfy context window token budget.")
|
| 86 |
-
|
| 87 |
-
# C. Construct Official Model Prompt
|
| 88 |
-
messages = [
|
| 89 |
-
{"role": "system", "content": system_instruction},
|
| 90 |
-
{"role": "user", "content": user_input}
|
| 91 |
-
]
|
| 92 |
-
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 93 |
-
|
| 94 |
-
# D. Run Model Inference
|
| 95 |
raw_output = chat_pipeline(
|
| 96 |
-
|
| 97 |
max_new_tokens=int(max_tokens),
|
| 98 |
do_sample=True,
|
| 99 |
temperature=float(temp),
|
| 100 |
-
top_p=
|
| 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 |
-
with gr.Blocks(
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
|
|
|
| 143 |
with gr.Row():
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
| 157 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from langchain_community.vectorstores import FAISS
|
| 5 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 6 |
+
from langchain_core.documents import Document
|
| 7 |
|
| 8 |
# ==========================================
|
| 9 |
+
# 1. INITIALIZE ENGINE & VECTOR DATA
|
| 10 |
# ==========================================
|
| 11 |
+
print("Loading Lightweight Embedding Engine...")
|
| 12 |
+
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 13 |
|
| 14 |
+
print("Initializing High-Performance Qwen Core on CPU...")
|
| 15 |
+
chat_pipeline = pipeline(
|
| 16 |
+
"text-generation",
|
| 17 |
+
model="Qwen/Qwen2.5-1.5B-Instruct",
|
| 18 |
+
device="cpu",
|
| 19 |
+
dtype=torch.float32
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
# Fact-checking RAG context database
|
| 23 |
+
mock_news_db = [
|
| 24 |
"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.",
|
| 25 |
"EV Industrial Lifecycle: Electric Vehicles emit zero greenhouse operational gases, but lithium-ion battery extraction increases heavy localized ecosystem toxicity by 42%.",
|
| 26 |
"Universal Basic Income: Comprehensive economic trials indicate UBI successfully lowers base poverty indexes but sparks minor macro-inflationary pressures across basic retail commodities."
|
| 27 |
]
|
| 28 |
+
documents = [Document(page_content=text) for text in mock_news_db]
|
| 29 |
+
vector_store = FAISS.from_documents(documents, embedding_model)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# ==========================================
|
| 33 |
+
# 2. FEW-SHOT PROMPT COMPILER & EXECUTION
|
| 34 |
# ==========================================
|
| 35 |
+
def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
|
| 36 |
+
if not user_input.strip():
|
| 37 |
+
return "โ ๏ธ **System Input Error:** Workspace field cannot be processed empty."
|
| 38 |
|
| 39 |
+
# Structural Instructions + Few-Shot Examples
|
| 40 |
+
if workspace_type == "debate":
|
| 41 |
+
retriever = vector_store.as_retriever(search_kwargs={"k": 1})
|
| 42 |
+
matched_docs = retriever.invoke(user_input)
|
| 43 |
+
context = matched_docs[0].page_content if matched_docs else "No specific context available."
|
| 44 |
|
| 45 |
+
system_instruction = (
|
| 46 |
+
"You are a sharp, polite adversarial debate assistant. Disagree with the user's stance. "
|
| 47 |
+
"Provide exactly one paragraph of logical counter-argument, then provide a score out of 10.\n\n"
|
| 48 |
+
f"VERIFIED CONTEXT TO USE: {context}\n\n"
|
| 49 |
+
"### GOOD EXAMPLE RESPONSE FORMAT:\n"
|
| 50 |
+
"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"
|
| 51 |
+
"**Argument Logic Score: 6/10**"
|
| 52 |
+
)
|
| 53 |
+
else: # Generalize mode
|
| 54 |
+
system_instruction = (
|
| 55 |
+
"You are an expert news editor. Translate complex, jargon-heavy statements into plain, simple English. "
|
| 56 |
+
"Output your answer as clear, high-level summary bullet points under 50 words total.\n\n"
|
| 57 |
+
"### GOOD EXAMPLE RESPONSE FORMAT:\n"
|
| 58 |
+
"* Global markets fell sharply due to sudden central bank interest rate changes.\n"
|
| 59 |
+
"* Local manufacturing activity slowed down to an all-time low."
|
| 60 |
+
)
|
| 61 |
|
| 62 |
+
# Construct Prompt using Official Qwen ChatML Template format
|
| 63 |
+
formatted_prompt = (
|
| 64 |
+
f"<|im_start|>system\n{system_instruction}\n"
|
| 65 |
+
"CRITICAL: Keep your response concise. Do not ramble. Complete your final sentence perfectly.<|im_end|>\n"
|
| 66 |
+
f"<|im_start|>user\n{user_input}<|im_end|>\n"
|
| 67 |
+
"<|im_start|>assistant\n"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# CPU Execution Pipeline
|
| 71 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
raw_output = chat_pipeline(
|
| 73 |
+
formatted_prompt,
|
| 74 |
max_new_tokens=int(max_tokens),
|
| 75 |
do_sample=True,
|
| 76 |
temperature=float(temp),
|
| 77 |
+
top_p=float(top_p),
|
| 78 |
+
top_k=40,
|
| 79 |
+
repetition_penalty=1.2
|
| 80 |
)
|
| 81 |
+
|
| 82 |
+
processed_text = raw_output[0]["generated_text"].split("<|im_start|>assistant\n")[-1].strip()
|
| 83 |
+
|
| 84 |
+
# Programmatic Clean Up: Ensure no trailing cut-off sentences are displayed
|
| 85 |
+
if processed_text and processed_text[-1] not in [".", "!", "?", '"', "*"]:
|
| 86 |
+
last_punctuation = max(processed_text.rfind("."), processed_text.rfind("!"), processed_text.rfind("?"))
|
| 87 |
+
if last_punctuation != -1:
|
| 88 |
+
processed_text = processed_text[:last_punctuation + 1]
|
| 89 |
+
|
| 90 |
+
return processed_text
|
| 91 |
|
| 92 |
+
except Exception as error:
|
| 93 |
+
return f"โ **Pipeline Fault:** Execution error on CPU node. Details: {str(error)}"
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# ==========================================
|
| 97 |
+
# 3. CUSTOM ENTERPRISE CSS INSPIRATION
|
| 98 |
+
# ==========================================
|
| 99 |
+
custom_css = """
|
| 100 |
+
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');
|
| 101 |
+
|
| 102 |
+
body, .gradio-container {
|
| 103 |
+
font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif !important;
|
| 104 |
+
background-color: #0B0F17 !important;
|
| 105 |
+
color: #F3F4F6 !important;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/* Header Branding */
|
| 109 |
+
.breadcrumb-text {
|
| 110 |
+
font-size: 12px;
|
| 111 |
+
font-weight: 700;
|
| 112 |
+
text-transform: uppercase;
|
| 113 |
+
letter-spacing: 0.08em;
|
| 114 |
+
color: #6366F1;
|
| 115 |
+
margin-bottom: 4px;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.main-title {
|
| 119 |
+
font-size: 32px;
|
| 120 |
+
font-weight: 800;
|
| 121 |
+
letter-spacing: -0.02em;
|
| 122 |
+
color: #FFFFFF;
|
| 123 |
+
margin-bottom: 6px;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.sub-title {
|
| 127 |
+
font-size: 15px;
|
| 128 |
+
color: #9CA3AF;
|
| 129 |
+
line-height: 1.5;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/* Metric KPI Dashboard Styling */
|
| 133 |
+
.kpi-container {
|
| 134 |
+
display: grid;
|
| 135 |
+
grid-template-columns: repeat(4, 1fr);
|
| 136 |
+
gap: 12px;
|
| 137 |
+
margin: 20px 0;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.kpi-card {
|
| 141 |
+
background: #111827;
|
| 142 |
+
border: 1px solid #1F2937;
|
| 143 |
+
border-radius: 12px;
|
| 144 |
+
padding: 16px 20px;
|
| 145 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.kpi-value {
|
| 149 |
+
font-size: 26px;
|
| 150 |
+
font-weight: 800;
|
| 151 |
+
color: #4F46E5;
|
| 152 |
+
letter-spacing: -0.02em;
|
| 153 |
+
}
|
| 154 |
|
| 155 |
+
.kpi-label {
|
| 156 |
+
font-size: 11px;
|
| 157 |
+
font-weight: 700;
|
| 158 |
+
text-transform: uppercase;
|
| 159 |
+
color: #9CA3AF;
|
| 160 |
+
letter-spacing: 0.05em;
|
| 161 |
+
margin-top: 4px;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* Custom Primary Button Styling */
|
| 165 |
+
button.primary-action-btn {
|
| 166 |
+
background: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%) !important;
|
| 167 |
+
border: none !important;
|
| 168 |
+
color: #FFFFFF !important;
|
| 169 |
+
font-weight: 700 !important;
|
| 170 |
+
border-radius: 8px !important;
|
| 171 |
+
padding: 12px 24px !important;
|
| 172 |
+
box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.4) !important;
|
| 173 |
+
transition: all 0.2s ease !important;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
button.primary-action-btn:hover {
|
| 177 |
+
transform: translateY(-1px) !important;
|
| 178 |
+
box-shadow: 0 6px 20px 0 rgba(79, 70, 229, 0.6) !important;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/* Form Container and Tab Cards */
|
| 182 |
+
.workspace-card {
|
| 183 |
+
background: #111827 !important;
|
| 184 |
+
border: 1px solid #1F2937 !important;
|
| 185 |
+
border-radius: 16px !important;
|
| 186 |
+
padding: 20px !important;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* Output Stream Terminal Panel */
|
| 190 |
+
.output-monitor {
|
| 191 |
+
background: #0F172A !important;
|
| 192 |
+
border: 1px solid #1E293B !important;
|
| 193 |
+
border-radius: 12px !important;
|
| 194 |
+
padding: 18px !important;
|
| 195 |
+
min-height: 240px;
|
| 196 |
+
}
|
| 197 |
+
"""
|
| 198 |
|
| 199 |
|
| 200 |
# ==========================================
|
| 201 |
+
# 4. MODULAR UI DASHBOARD (GRADIO 6.0)
|
| 202 |
# ==========================================
|
| 203 |
+
with gr.Blocks(css=custom_css, title="Enterprise AI News Suite") as demo:
|
| 204 |
+
|
| 205 |
+
# 1. Executive Top Bar
|
| 206 |
+
with gr.Row():
|
| 207 |
+
with gr.Column(scale=3):
|
| 208 |
+
gr.Markdown(
|
| 209 |
+
"<div class='breadcrumb-text'>AI AGENT LIBRARY > NEWS INTELLIGENCE & DEBATE</div>"
|
| 210 |
+
"<div class='main-title'>Enterprise News Debate & Summary Suite</div>"
|
| 211 |
+
"<div class='sub-title'>Localized FAISS vector embeddings paired with few-shot prompt anchoring for deterministic, zero-hallucination analysis on CPU clusters.</div>"
|
| 212 |
+
)
|
| 213 |
+
with gr.Column(scale=1):
|
| 214 |
+
gr.HighlightedText(
|
| 215 |
+
value=[("SYSTEM ONLINE", "๐ข CPU Cluster")],
|
| 216 |
+
show_label=False,
|
| 217 |
+
combine_adjacent=True
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
# 2. Executive KPI Metrics Grid (Inspired by Webtures template)
|
| 221 |
+
gr.HTML("""
|
| 222 |
+
<div class="kpi-container">
|
| 223 |
+
<div class="kpi-card">
|
| 224 |
+
<div class="kpi-value">1.5B</div>
|
| 225 |
+
<div class="kpi-label">Qwen Core Parameters</div>
|
| 226 |
+
</div>
|
| 227 |
+
<div class="kpi-card">
|
| 228 |
+
<div class="kpi-value">FAISS</div>
|
| 229 |
+
<div class="kpi-label">Vector RAG Engine</div>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="kpi-card">
|
| 232 |
+
<div class="kpi-value">32-Bit</div>
|
| 233 |
+
<div class="kpi-label">Precision Runtime</div>
|
| 234 |
+
</div>
|
| 235 |
+
<div class="kpi-card">
|
| 236 |
+
<div class="kpi-value">100%</div>
|
| 237 |
+
<div class="kpi-label">CPU Localized Execution</div>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
""")
|
| 241 |
|
| 242 |
+
# 3. Main Operational Workspaces
|
| 243 |
with gr.Row():
|
| 244 |
+
|
| 245 |
+
# Left Panel: Input & Workspaces
|
| 246 |
+
with gr.Column(scale=12, elem_classes=["workspace-card"]):
|
| 247 |
+
gr.Markdown("### ๐ ๏ธ Agent Execution Workspaces")
|
| 248 |
+
|
| 249 |
+
with gr.Tabs() as active_workspace_tabs:
|
| 250 |
+
|
| 251 |
+
# Tab 1: Debate Module
|
| 252 |
+
with gr.Tab(label="๐๏ธ๏ธ News Debate Agent", id=0):
|
| 253 |
+
gr.Markdown("*State a topic or stance. The agent will pull verified context, debate your argument, and issue a score.*")
|
| 254 |
+
|
| 255 |
+
debate_example_picker = gr.Dropdown(
|
| 256 |
+
label="๐ก Preset Topics & Stances",
|
| 257 |
+
choices=[
|
| 258 |
+
"LLMs are indispensable for application development.",
|
| 259 |
+
"Electric vehicles are the only way to save the environment.",
|
| 260 |
+
"Universal Basic Income will just make people lazy."
|
| 261 |
+
]
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
debate_text_input = gr.Textbox(
|
| 265 |
+
label="Your Stance *",
|
| 266 |
+
placeholder="Select or paste your claim here...",
|
| 267 |
+
lines=3
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
debate_example_picker.change(fn=lambda x: x, inputs=debate_example_picker, outputs=debate_text_input)
|
| 271 |
+
|
| 272 |
+
run_debate_action = gr.Button("Deploy Counter-Argument Engine", variant="primary", elem_classes=["primary-action-btn"])
|
| 273 |
+
|
| 274 |
+
# Tab 2: Text Simplification Module
|
| 275 |
+
with gr.Tab(label="๐ฐ Snippet Generalizer", id=1):
|
| 276 |
+
gr.Markdown("*Paste complex, jargon-heavy news reports to convert them into concise executive summaries.*")
|
| 277 |
+
|
| 278 |
+
generalizer_example_picker = gr.Dropdown(
|
| 279 |
+
label="๐ก Preset News Snippets",
|
| 280 |
+
choices=[
|
| 281 |
+
"Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations.",
|
| 282 |
+
"The ecosystem validation vectors indicate substantial degradation in sub-surface lithospheric layers owing to chemical manufacturing runoffs, sparking compliance friction."
|
| 283 |
+
],
|
| 284 |
+
value="Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations."
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
simplify_text_input = gr.Textbox(
|
| 288 |
+
label="Complex News Snippet *",
|
| 289 |
+
lines=4,
|
| 290 |
+
value="Despite aggressive macroeconomic headwinds and structural quantitative tightening by central banking systems, retail index trends demonstrated non-linear elasticity during fiscal evaluations.",
|
| 291 |
+
placeholder="Paste text block or official reports here..."
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
generalizer_example_picker.change(fn=lambda x: x, inputs=generalizer_example_picker, outputs=simplify_text_input)
|
| 295 |
+
|
| 296 |
+
run_simplifier_action = gr.Button("Deploy Generalization Engine", variant="primary", elem_classes=["primary-action-btn"])
|
| 297 |
+
|
| 298 |
+
# Runtime Tuning Accordion
|
| 299 |
+
with gr.Accordion("โ๏ธ Engine Tuning & Runtime Parameters", open=False):
|
| 300 |
+
max_tokens_val = gr.Slider(minimum=64, maximum=256, value=140, step=16, label="Max Tokens")
|
| 301 |
+
temp_val = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Temperature (Low = Deterministic)")
|
| 302 |
+
top_p_val = gr.Slider(minimum=0.50, maximum=1.00, value=0.85, step=0.05, label="Top-p Sampling")
|
| 303 |
+
|
| 304 |
+
# Right Panel: Output Monitor
|
| 305 |
+
with gr.Column(scale=10, elem_classes=["workspace-card"]):
|
| 306 |
+
gr.Markdown("### ๐ฅ๏ธ Real-Time Output Stream")
|
| 307 |
+
|
| 308 |
+
with gr.Column(elem_classes=["output-monitor"]):
|
| 309 |
+
active_output_panel = gr.Markdown(
|
| 310 |
+
value="*System initialized and ready. Select an execution workspace and click deploy to parse stream output.*"
|
| 311 |
+
)
|
| 312 |
|
| 313 |
+
# ==========================================
|
| 314 |
+
# 5. EVENT CONTROLLERS
|
| 315 |
+
# ==========================================
|
| 316 |
+
run_debate_action.click(
|
| 317 |
+
fn=lambda user_in, tokens, t, p: execution_engine("debate", user_in, tokens, t, p),
|
| 318 |
+
inputs=[debate_text_input, max_tokens_val, temp_val, top_p_val],
|
| 319 |
+
outputs=active_output_panel
|
| 320 |
+
)
|
| 321 |
|
| 322 |
+
run_simplifier_action.click(
|
| 323 |
+
fn=lambda user_in, tokens, t, p: execution_engine("generalize", user_in, tokens, t, p),
|
| 324 |
+
inputs=[simplify_text_input, max_tokens_val, temp_val, top_p_val],
|
| 325 |
+
outputs=active_output_panel
|
| 326 |
+
)
|
| 327 |
|
| 328 |
if __name__ == "__main__":
|
| 329 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|