Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,60 +2,34 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
-
model_id = "
|
| 8 |
|
| 9 |
-
print("Loading the Digital Vaccine model...")
|
| 10 |
pipe = pipeline(
|
| 11 |
"text-generation",
|
| 12 |
model=model_id,
|
| 13 |
device_map="auto",
|
| 14 |
-
torch_dtype=
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
def digital_wellness_intervention(user_input, scroll_velocity):
|
| 18 |
-
#
|
| 19 |
-
# We simulate a "Zombiescroll" detection if velocity is high and input is low-value
|
| 20 |
is_zombiescroll = scroll_velocity > 70
|
| 21 |
|
| 22 |
-
prompt
|
| 23 |
-
|
| 24 |
-
State: {'Zombiescroll' if is_zombiescroll else 'Intentional Browsing'}
|
| 25 |
-
User's last thought: {user_input}
|
| 26 |
|
| 27 |
-
|
| 28 |
-
intervention to help the user regain focus and break the dopamine loop.
|
| 29 |
-
"""
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
intervention_text = outputs[0]["generated_text"][-1]["content"]
|
| 35 |
|
| 36 |
status = "⚠️ INTERVENTION TRIGGERED" if is_zombiescroll else "✅ FOCUS MAINTAINED"
|
| 37 |
return status, intervention_text
|
| 38 |
|
| 39 |
# Gradio Interface
|
| 40 |
-
with gr.Blocks(theme
|
| 41 |
-
gr.Markdown("# 🧬 The Digital Vaccine: AI-in-the-Loop")
|
| 42 |
-
gr.Markdown("This Space simulates an edge-AI 'Circuit Breaker' using a MedGemma-style architecture.")
|
| 43 |
-
|
| 44 |
-
with gr.Row():
|
| 45 |
-
with gr.Column():
|
| 46 |
-
input_text = gr.Textbox(label="What are you looking for right now?", placeholder="e.g., Just checking notifications...")
|
| 47 |
-
velocity = gr.Slider(minimum=0, maximum=100, value=20, label="Simulated Scroll Velocity (Dopamine Intensity)")
|
| 48 |
-
btn = gr.Button("Analyze My State", variant="primary")
|
| 49 |
-
|
| 50 |
-
with gr.Column():
|
| 51 |
-
status_output = gr.Label(label="System Status")
|
| 52 |
-
intervention_output = gr.Textbox(label="MedGemma Intervention")
|
| 53 |
-
|
| 54 |
-
btn.click(digital_wellness_intervention, inputs=[input_text, velocity], outputs=[status_output, intervention_output])
|
| 55 |
-
|
| 56 |
-
gr.Examples(
|
| 57 |
-
examples=[["Learning about Quantum Physics", 10], ["I'm bored and just clicking links", 85]],
|
| 58 |
-
inputs=[input_text, velocity]
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Switching to an UNGATED model to bypass the 403 error
|
| 6 |
+
# Phi-3 is a high-performance Small Language Model (SLM) from Microsoft
|
| 7 |
+
model_id = "microsoft/Phi-3-mini-4k-instruct"
|
| 8 |
|
| 9 |
+
print("Loading the Digital Vaccine model (Phi-3)...")
|
| 10 |
pipe = pipeline(
|
| 11 |
"text-generation",
|
| 12 |
model=model_id,
|
| 13 |
device_map="auto",
|
| 14 |
+
torch_dtype="auto",
|
| 15 |
+
trust_remote_code=True
|
| 16 |
)
|
| 17 |
|
| 18 |
def digital_wellness_intervention(user_input, scroll_velocity):
|
| 19 |
+
# Logic: High velocity (>70) triggers the 'Zombiescroll' detection
|
|
|
|
| 20 |
is_zombiescroll = scroll_velocity > 70
|
| 21 |
|
| 22 |
+
# Updated prompt format for Phi-3's chat template
|
| 23 |
+
prompt = f"<|user|>\nContext: The user is in a high-velocity scrolling loop.\nState: {'Zombiescroll' if is_zombiescroll else 'Intentional Browsing'}\nUser thought: {user_input}\nTask: Provide a 2-sentence 'Micro-CBT' intervention to help them break the trance.<|end|>\n<|assistant|>"
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
outputs = pipe(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Extracting the assistant's response
|
| 28 |
+
full_text = outputs[0]["generated_text"]
|
| 29 |
+
intervention_text = full_text.split("<|assistant|>")[-1].strip()
|
|
|
|
| 30 |
|
| 31 |
status = "⚠️ INTERVENTION TRIGGERED" if is_zombiescroll else "✅ FOCUS MAINTAINED"
|
| 32 |
return status, intervention_text
|
| 33 |
|
| 34 |
# Gradio Interface
|
| 35 |
+
with gr.Blocks(theme
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|