pravin0077 commited on
Commit
1b7a9d8
·
verified ·
1 Parent(s): 83184e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -15,15 +15,13 @@ login(token=hf_token, add_to_git_credential=True)
15
 
16
  # Define available languages with their respective Helsinki model names
17
  language_models = {
18
- "Abkhaz": "Helsinki-NLP/opus-mt-abk-en",
19
  "Arabic": "Helsinki-NLP/opus-mt-ar-en",
20
- "Azerbaijani": "Helsinki-NLP/opus-mt-az-en",
21
  "Bengali": "Helsinki-NLP/opus-mt-bn-en",
22
- "Chinese": "Helsinki-NLP/opus-mt-zh-en",
23
- "Danish": "Helsinki-NLP/opus-mt-da-en",
24
- "Finnish": "Helsinki-NLP/opus-mt-fi-en",
25
  "French": "Helsinki-NLP/opus-mt-fr-en",
26
  "Hindi": "Helsinki-NLP/opus-mt-hi-en",
 
 
 
27
  "Tamil": "Helsinki-NLP/opus-mt-mul-en" # Using multilingual model for Tamil
28
  }
29
 
@@ -39,10 +37,10 @@ flux_API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FL
39
  flux_headers = {"Authorization": f"Bearer {hf_token}"}
40
 
41
  # Function for translation
42
- def translate_text(tamil_text, language):
43
  translator = load_translation_pipeline(language)
44
  try:
45
- translation = translator(tamil_text, max_length=40)
46
  translated_text = translation[0]['translation_text']
47
  return translated_text
48
  except Exception as e:
@@ -78,8 +76,8 @@ def generate_creative_text(translated_text):
78
  return None
79
 
80
  # Function to handle the full workflow
81
- def translate_generate_image_and_text(tamil_text, language):
82
- translated_text = translate_text(tamil_text, language)
83
  image = generate_image(translated_text)
84
  creative_text = generate_creative_text(translated_text)
85
  return translated_text, creative_text, image
 
15
 
16
  # Define available languages with their respective Helsinki model names
17
  language_models = {
 
18
  "Arabic": "Helsinki-NLP/opus-mt-ar-en",
 
19
  "Bengali": "Helsinki-NLP/opus-mt-bn-en",
 
 
 
20
  "French": "Helsinki-NLP/opus-mt-fr-en",
21
  "Hindi": "Helsinki-NLP/opus-mt-hi-en",
22
+ "Russian": "Helsinki-NLP/opus-mt-ru-en",
23
+ "German": "Helsinki-NLP/opus-mt-de-en",
24
+ "Spanish": "Helsinki-NLP/opus-mt-es-en",
25
  "Tamil": "Helsinki-NLP/opus-mt-mul-en" # Using multilingual model for Tamil
26
  }
27
 
 
37
  flux_headers = {"Authorization": f"Bearer {hf_token}"}
38
 
39
  # Function for translation
40
+ def translate_text(text, language):
41
  translator = load_translation_pipeline(language)
42
  try:
43
+ translation = translator(text, max_length=40)
44
  translated_text = translation[0]['translation_text']
45
  return translated_text
46
  except Exception as e:
 
76
  return None
77
 
78
  # Function to handle the full workflow
79
+ def translate_generate_image_and_text(input_text, language):
80
+ translated_text = translate_text(input_text, language)
81
  image = generate_image(translated_text)
82
  creative_text = generate_creative_text(translated_text)
83
  return translated_text, creative_text, image