sandipghimire commited on
Commit
8c2cbb0
·
verified ·
1 Parent(s): 81e394f

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -17,6 +17,9 @@ adapter_path = default_adapter_id if not os.path.exists("./filtered_adapter") el
17
  model = None
18
  tokenizer = None
19
 
 
 
 
20
  @spaces.GPU
21
  def translate(text):
22
  global model, tokenizer
@@ -24,6 +27,13 @@ def translate(text):
24
  if not text.strip():
25
  return "Please enter some text to translate."
26
 
 
 
 
 
 
 
 
27
  # Lazy load model and tokenizer on ZeroGPU
28
  if model is None or tokenizer is None:
29
  print("Initializing tokenizer and loading model on ZeroGPU...")
@@ -79,7 +89,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="indigo"))
79
  gr.Markdown(
80
  """
81
  # 🇳🇵 X-ALMA-13B English-to-Nepali Translation Model (PRO)
82
- This translation model is fine-tuned on legal, administrative, and general English-to-Nepali parallel datasets.
83
  """
84
  )
85
 
@@ -100,15 +110,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="indigo"))
100
  interactive=False
101
  )
102
 
103
- gr.Examples(
104
- examples=[
105
- "Based on all the testimony and documents the hearing record provided, the ALJ correctly denied the appellant’s request for 10 hours on school days and 12 hours on non-school days of HHA services.",
106
- "The appellant's representative requested 8.5 hours on school days and 9.75 hours on non-school days.",
107
- "Arun Gupto, a professor of English literature and cultural studies, has long been a revered intellectual figure. Known for his heavyweight academic publications with prestigious international publishing houses like Routledge and Rupa, Gupto is a scholar who commands deep respect in academic circles."
108
- ],
109
- inputs=input_text
110
- )
111
-
112
  translate_btn.click(fn=translate, inputs=input_text, outputs=output_text)
113
 
114
  if __name__ == "__main__":
 
17
  model = None
18
  tokenizer = None
19
 
20
+ # Check if CUDA is available in the container
21
+ cuda_available = torch.cuda.is_available()
22
+
23
  @spaces.GPU
24
  def translate(text):
25
  global model, tokenizer
 
27
  if not text.strip():
28
  return "Please enter some text to translate."
29
 
30
+ if not cuda_available:
31
+ return (
32
+ "⚠️ Error: This Space is currently running on the CPU basic tier. "
33
+ "To enable the translation model, please go to the Settings tab of this Space, "
34
+ "scroll down to 'Space Hardware', and select 'ZeroGPU' or a GPU tier (requires credit card verification or a PRO account)."
35
+ )
36
+
37
  # Lazy load model and tokenizer on ZeroGPU
38
  if model is None or tokenizer is None:
39
  print("Initializing tokenizer and loading model on ZeroGPU...")
 
89
  gr.Markdown(
90
  """
91
  # 🇳🇵 X-ALMA-13B English-to-Nepali Translation Model (PRO)
92
+ This translation model is fine-tuned on administrative and general English-to-Nepali parallel datasets.
93
  """
94
  )
95
 
 
110
  interactive=False
111
  )
112
 
 
 
 
 
 
 
 
 
 
113
  translate_btn.click(fn=translate, inputs=input_text, outputs=output_text)
114
 
115
  if __name__ == "__main__":