gk2410 commited on
Commit
0e7f9cb
·
verified ·
1 Parent(s): 12171fa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+
5
+ # Using gemma-2-2b-it for high-speed edge simulation
6
+ # In a full clinical app, we would swap this for 'google/medgemma-2b'
7
+ model_id = "google/gemma-2-2b-it"
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=torch.bfloat16
15
+ )
16
+
17
+ def digital_wellness_intervention(user_input, scroll_velocity):
18
+ # Engineering the "Circuit Breaker" Logic
19
+ # We simulate a "Zombiescroll" detection if velocity is high and input is low-value
20
+ is_zombiescroll = scroll_velocity > 70
21
+
22
+ prompt = f"""
23
+ Context: A user is currently in a high-velocity scrolling loop.
24
+ State: {'Zombiescroll' if is_zombiescroll else 'Intentional Browsing'}
25
+ User's last thought: {user_input}
26
+
27
+ Task: Act as a clinical AI (MedGemma-style). Provide a short, 2-sentence 'Micro-CBT'
28
+ intervention to help the user regain focus and break the dopamine loop.
29
+ """
30
+
31
+ messages = [{"role": "user", "content": prompt}]
32
+ outputs = pipe(messages, max_new_tokens=100, do_sample=True, temperature=0.7)
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=gr.themes.Soft()) as demo:
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()