afnotes commited on
Commit
2569a42
·
1 Parent(s): c0d02bd

cuda thing idk

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -13,7 +13,8 @@ ADAPTER_MODEL_ID = "afnotes/Qwen3-4B-YeI-LoRA"
13
  @spaces.GPU
14
  def load_model():
15
  print(f"Loading tokenizer from: {ADAPTER_MODEL_ID}")
16
- tokenizer = AutoTokenizer.from_pretrained(ADAPTER_MODEL_ID)
 
17
 
18
  if tokenizer.eos_token is None:
19
  tokenizer.eos_token = "<|endoftext|>"
@@ -24,7 +25,7 @@ def load_model():
24
 
25
  print(f"Loading base model: {BASE_MODEL_ID}")
26
 
27
- # Determine device (CUDA if available, else CPU)
28
  device_to_load = "cuda" if torch.cuda.is_available() else "cpu"
29
  print(f"Using device: {device_to_load}")
30
 
@@ -80,10 +81,11 @@ def load_model():
80
  return tokenizer, model
81
 
82
  # --- Generation Function for Gradio ---
 
83
  def generate_kanye_tweet(prompt_text, max_new_tokens, temperature, top_p, repetition_penalty):
84
  print(f"--- Generating for prompt ---\n'{prompt_text}'")
85
 
86
- # Load model and tokenizer dynamically for each request
87
  tokenizer, model = load_model()
88
 
89
  inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
@@ -135,13 +137,13 @@ iface = gr.Interface(
135
  title="🎙️ Ye-I: Kanye Tweet Generator (4B Model) 🎤",
136
  description="Generate Kanye West-style tweet snippets using a fine-tuned Qwen3-4B model. Optimized for ZeroGPU.",
137
  examples=[
138
- ["I HATE"],
139
- ["My next album will be called"],
140
- ["Fashion is dead without"],
141
- ["Only God can judge"]
142
  ],
143
  allow_flagging="never"
144
  )
145
 
146
  if __name__ == "__main__":
147
- iface.launch()
 
 
13
  @spaces.GPU
14
  def load_model():
15
  print(f"Loading tokenizer from: {ADAPTER_MODEL_ID}")
16
+ # Load tokenizer without triggering CUDA
17
+ tokenizer = AutoTokenizer.from_pretrained(ADAPTER_MODEL_ID, use_fast=False)
18
 
19
  if tokenizer.eos_token is None:
20
  tokenizer.eos_token = "<|endoftext|>"
 
25
 
26
  print(f"Loading base model: {BASE_MODEL_ID}")
27
 
28
+ # Check for CUDA availability inside the @spaces.GPU context
29
  device_to_load = "cuda" if torch.cuda.is_available() else "cpu"
30
  print(f"Using device: {device_to_load}")
31
 
 
81
  return tokenizer, model
82
 
83
  # --- Generation Function for Gradio ---
84
+ @spaces.GPU
85
  def generate_kanye_tweet(prompt_text, max_new_tokens, temperature, top_p, repetition_penalty):
86
  print(f"--- Generating for prompt ---\n'{prompt_text}'")
87
 
88
+ # Load model and tokenizer within the @spaces.GPU context
89
  tokenizer, model = load_model()
90
 
91
  inputs = tokenizer(prompt_text, return_tensors="pt").to(model.device)
 
137
  title="🎙️ Ye-I: Kanye Tweet Generator (4B Model) 🎤",
138
  description="Generate Kanye West-style tweet snippets using a fine-tuned Qwen3-4B model. Optimized for ZeroGPU.",
139
  examples=[
140
+ ["I HATE", 50, 0.9, 0.95, 1.0],
141
+ ["My next album will be called", 50, 0.9, 0.95, 1.0],
142
+ ["Fashion is dead without", 50, 0.9, 0.95, 1.0],
 
143
  ],
144
  allow_flagging="never"
145
  )
146
 
147
  if __name__ == "__main__":
148
+ # Disable SSR mode to avoid potential main process issues
149
+ iface.launch(ssr_mode=False)