Pisethan commited on
Commit
388ecb4
Β·
verified Β·
1 Parent(s): 38dbae2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,17 +1,17 @@
 
1
  import gradio as gr
2
  import torch
3
  from transformers import pipeline
4
 
5
- # βœ… Auto-select device: GPU (if available), else CPU
6
- device = 0 if torch.cuda.is_available() else -1
7
-
8
- # βœ… Load text generation pipeline
9
- pipe = pipeline(
10
- "text-generation",
11
- model="Pisethan/khmer-lesson-model-v2",
12
- tokenizer="Pisethan/khmer-lesson-model",
13
- device=device # Use GPU if available
14
- )
15
 
16
  # βœ… Dropdown choices
17
  grade_options = ["1", "2", "3", "4", "5", "6"]
@@ -74,3 +74,5 @@ with gr.Blocks() as demo:
74
 
75
  # βœ… Launch app with public link
76
  demo.launch(share=True)
 
 
 
1
+ from spaces import GPU
2
  import gradio as gr
3
  import torch
4
  from transformers import pipeline
5
 
6
+ @GPU # πŸ‘ˆ REQUIRED to activate GPU on Hugging Face ZeroGPU
7
+ def main():
8
+ device = 0 if torch.cuda.is_available() else -1
9
+ pipe = pipeline(
10
+ "text-generation",
11
+ model="Pisethan/khmer-lesson-model-v2",
12
+ tokenizer="Pisethan/khmer-lesson-model",
13
+ device=device
14
+ )
 
15
 
16
  # βœ… Dropdown choices
17
  grade_options = ["1", "2", "3", "4", "5", "6"]
 
74
 
75
  # βœ… Launch app with public link
76
  demo.launch(share=True)
77
+
78
+ main()