anisgtboi commited on
Commit
ec21afd
·
verified ·
1 Parent(s): ea3de62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -6,16 +6,15 @@ import gradio as gr
6
  # Try import transformers; if missing the app will show a clear error message in logs.
7
  try:
8
  from transformers import pipeline
9
- except Exception as e:
10
- pipeline = None
11
- print("transformers import error:", e)
12
 
13
- # --- CONFIG: use lightweight OPUS-MT models for CPU-friendly translation ---
14
- MODEL_EN_TO_BN = "shhossain/opus-mt-en-to-bn"
15
- MODEL_BN_TO_EN = "Helsinki-NLP/opus-mt-bn-en"
16
 
17
- # cache of loaded pipelines
18
- _loaded = {}
 
 
 
19
 
20
  def safe_load_pipeline(model_name):
21
  """Load a translation pipeline lazily and return a tuple (success, message)."""
 
6
  # Try import transformers; if missing the app will show a clear error message in logs.
7
  try:
8
  from transformers import pipeline
9
+ import os
 
 
10
 
11
+ auth_token = os.getenv("HF_API_TOKEN")
 
 
12
 
13
+ translator = pipeline(
14
+ "translation",
15
+ model="Helsinki-NLP/opus-mt-en-bn", # or your chosen model
16
+ token=auth_token
17
+ )
18
 
19
  def safe_load_pipeline(model_name):
20
  """Load a translation pipeline lazily and return a tuple (success, message)."""