Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ chat_pipeline = pipeline(
|
|
| 19 |
dtype=torch.float32
|
| 20 |
)
|
| 21 |
|
| 22 |
-
#
|
| 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%.",
|
|
@@ -30,7 +30,7 @@ vector_store = FAISS.from_documents(documents, embedding_model)
|
|
| 30 |
|
| 31 |
|
| 32 |
# ==========================================
|
| 33 |
-
# 2. FEW-SHOT PROMPT COMPILER
|
| 34 |
# ==========================================
|
| 35 |
def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
|
| 36 |
if not user_input.strip():
|
|
@@ -76,13 +76,12 @@ def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
|
|
| 76 |
temperature=float(temp),
|
| 77 |
top_p=float(top_p),
|
| 78 |
top_k=40,
|
| 79 |
-
repetition_penalty=1.2
|
| 80 |
-
return_full_text=False # Direct return optimization (prevents prompt duplication)
|
| 81 |
)
|
| 82 |
|
| 83 |
-
processed_text = raw_output[0]["generated_text"].strip()
|
| 84 |
|
| 85 |
-
# Programmatic Clean Up: Ensure no
|
| 86 |
if processed_text and processed_text[-1] not in [".", "!", "?", '"', "*"]:
|
| 87 |
last_punctuation = max(processed_text.rfind("."), processed_text.rfind("!"), processed_text.rfind("?"))
|
| 88 |
if last_punctuation != -1:
|
|
@@ -95,7 +94,7 @@ def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
|
|
| 95 |
|
| 96 |
|
| 97 |
# ==========================================
|
| 98 |
-
# 3. MODULAR UI DASHBOARD (GRADIO 6.0
|
| 99 |
# ==========================================
|
| 100 |
with gr.Blocks() as demo:
|
| 101 |
|
|
@@ -109,7 +108,7 @@ with gr.Blocks() as demo:
|
|
| 109 |
"concise outputs optimized for zero-error execution on base CPU clusters."
|
| 110 |
)
|
| 111 |
|
| 112 |
-
# Status Module Panel
|
| 113 |
with gr.Column(scale=1):
|
| 114 |
gr.HighlightedText(value=[("ONLINE", "🟢 NLP Match Engine Status")], show_label=False)
|
| 115 |
gr.Markdown(
|
|
@@ -166,7 +165,7 @@ with gr.Blocks() as demo:
|
|
| 166 |
|
| 167 |
gr.HTML("<div style='margin-bottom: 20px;'></div>")
|
| 168 |
|
| 169 |
-
# Param Configuration Module
|
| 170 |
with gr.Accordion("⚙️ Runtime Parameter Tuning", open=False):
|
| 171 |
max_tokens_val = gr.Slider(minimum=64, maximum=256, value=140, step=16, label="Max tokens")
|
| 172 |
temp_val = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Temperature (Low = Deterministic)")
|
|
|
|
| 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%.",
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
# ==========================================
|
| 33 |
+
# 2. FEW-SHOT PROMPT COMPILER
|
| 34 |
# ==========================================
|
| 35 |
def execution_engine(workspace_type, user_input, max_tokens, temp, top_p):
|
| 36 |
if not user_input.strip():
|
|
|
|
| 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:
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
# ==========================================
|
| 97 |
+
# 3. MODULAR UI DASHBOARD (GRADIO 6.0)
|
| 98 |
# ==========================================
|
| 99 |
with gr.Blocks() as demo:
|
| 100 |
|
|
|
|
| 108 |
"concise outputs optimized for zero-error execution on base CPU clusters."
|
| 109 |
)
|
| 110 |
|
| 111 |
+
# Status Module Panel
|
| 112 |
with gr.Column(scale=1):
|
| 113 |
gr.HighlightedText(value=[("ONLINE", "🟢 NLP Match Engine Status")], show_label=False)
|
| 114 |
gr.Markdown(
|
|
|
|
| 165 |
|
| 166 |
gr.HTML("<div style='margin-bottom: 20px;'></div>")
|
| 167 |
|
| 168 |
+
# Param Configuration Module (Hidden Tuning to keep CPU fast and reliable)
|
| 169 |
with gr.Accordion("⚙️ Runtime Parameter Tuning", open=False):
|
| 170 |
max_tokens_val = gr.Slider(minimum=64, maximum=256, value=140, step=16, label="Max tokens")
|
| 171 |
temp_val = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Temperature (Low = Deterministic)")
|