lsadouk1111 commited on
Commit
63b9598
·
verified ·
1 Parent(s): 87dc88d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -6,30 +6,14 @@ Gradio demo app for Hugging Face Spaces
6
  import json
7
  import gradio as gr
8
  import torch
9
- from unsloth import FastModel
10
  import spaces
11
 
12
-
13
  # ── Model loading ─────────────────────────────────────────────────────────────
14
  MODEL_ID = "lsadouk1111/VisualStep"
15
 
16
  model = None
17
  tokenizer = None
18
 
19
- def load_model():
20
- global model, tokenizer
21
- if model is None:
22
- print("Loading VisualStep model...")
23
- model, tokenizer = FastModel.from_pretrained(
24
- model_name=MODEL_ID,
25
- max_seq_length=512,
26
- load_in_4bit=True,
27
- dtype=None,
28
- )
29
- FastModel.for_inference(model)
30
- model.eval()
31
- print("Model ready.")
32
-
33
  # ── System prompt ─────────────────────────────────────────────────────────────
34
  SYSTEM_PROMPT = """You are an expert in ADHD classroom accommodations for primary school children aged 5-10.
35
  Transform the teacher's spoken classroom instruction into an ADHD-adapted visual step card.
@@ -75,9 +59,24 @@ def get_emoji(icon):
75
  # ── Generation ────────────────────────────────────────────────────────────────
76
  @spaces.GPU
77
  def generate_step_card(instruction, year, subject):
 
 
78
  if not instruction.strip():
79
  return "Please enter a classroom instruction."
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  messages = [
82
  {"role": "system", "content": SYSTEM_PROMPT},
83
  {"role": "user", "content": f"Year: {year} | Subject: {subject} | Instruction: {instruction}"},
@@ -202,4 +201,4 @@ The model was fine-tuned on VisualStep-2K, a dataset of 2,000 spoken classroom i
202
  All inference runs locally — no data is sent to external servers.
203
  """)
204
 
205
- demo.launch()
 
6
  import json
7
  import gradio as gr
8
  import torch
 
9
  import spaces
10
 
 
11
  # ── Model loading ─────────────────────────────────────────────────────────────
12
  MODEL_ID = "lsadouk1111/VisualStep"
13
 
14
  model = None
15
  tokenizer = None
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # ── System prompt ─────────────────────────────────────────────────────────────
18
  SYSTEM_PROMPT = """You are an expert in ADHD classroom accommodations for primary school children aged 5-10.
19
  Transform the teacher's spoken classroom instruction into an ADHD-adapted visual step card.
 
59
  # ── Generation ────────────────────────────────────────────────────────────────
60
  @spaces.GPU
61
  def generate_step_card(instruction, year, subject):
62
+ global model, tokenizer
63
+
64
  if not instruction.strip():
65
  return "Please enter a classroom instruction."
66
 
67
+ # Load model on first call (inside GPU context)
68
+ if model is None:
69
+ from unsloth import FastModel
70
+ global model, tokenizer
71
+ model, tokenizer = FastModel.from_pretrained(
72
+ model_name=MODEL_ID,
73
+ max_seq_length=512,
74
+ load_in_4bit=True,
75
+ dtype=None,
76
+ )
77
+ FastModel.for_inference(model)
78
+ model.eval()
79
+
80
  messages = [
81
  {"role": "system", "content": SYSTEM_PROMPT},
82
  {"role": "user", "content": f"Year: {year} | Subject: {subject} | Instruction: {instruction}"},
 
201
  All inference runs locally — no data is sent to external servers.
202
  """)
203
 
204
+ demo.launch()