|
|
|
import os |
|
from groq import Groq |
|
from gtts import gTTS |
|
import streamlit as st |
|
|
|
|
|
os.environ["GROQ_API_KEY"] = "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" |
|
|
|
|
|
api_key = os.environ.get("GROQ_API_KEY") |
|
client = Groq(api_key=api_key) |
|
|
|
|
|
def generate_happy_new_year(language_code): |
|
|
|
translations = { |
|
"en": "Happy New Year", |
|
"ur": "نیا سال مبارک ہو", |
|
"hi": "नया साल मुबारक हो", |
|
"bn": "শুভ নববর্ষ", |
|
"es": "Feliz Año Nuevo", |
|
"fr": "Bonne année", |
|
"de": "Frohes neues Jahr", |
|
"it": "Buon anno", |
|
"ar": "سنة جديدة سعيدة", |
|
"zh": "新年快乐", |
|
"th": "สวัสดีปีใหม่", |
|
"tr": "Mutlu Yıllar", |
|
"pa": "ਨਵਾਂ ਸਾਲ ਮੁਬਾਰਕ ਹੋ", |
|
"ps": "نوی کال مو مبارک شه", |
|
"ja": "新年おめでとうございます" |
|
} |
|
|
|
return translations.get(language_code, "Happy New Year") |
|
|
|
|
|
def text_to_speech(text, language_code='en'): |
|
tts = gTTS(text=text, lang=language_code) |
|
audio_path = f"/tmp/happy_new_year_{language_code}.mp3" |
|
tts.save(audio_path) |
|
return audio_path |
|
|
|
|
|
st.title("Happy New Year in Multiple Languages") |
|
st.write("Select a language to generate 'Happy New Year' text and hear it!") |
|
|
|
|
|
language_code = st.selectbox("Choose a Language", ["en", "ur", "hi", "bn", "es", "fr", "de", "it", "ar", "zh", "th", "tr", "pa", "ps", "ja"]) |
|
|
|
|
|
happy_new_year_text = generate_happy_new_year(language_code) |
|
|
|
|
|
st.write(f"Generated Text in {language_code.upper()}: {happy_new_year_text}") |
|
|
|
|
|
audio_file = text_to_speech(happy_new_year_text, language_code) |
|
|
|
|
|
st.audio(audio_file, format="audio/mp3") |
|
|
|
|
|
language_notes = { |
|
"en": "The text is in English.", |
|
"ur": "The text is in Urdu.", |
|
"hi": "The text is in Hindi.", |
|
"bn": "The text is in Bengali.", |
|
"es": "The text is in Spanish.", |
|
"fr": "The text is in French.", |
|
"de": "The text is in German.", |
|
"it": "The text is in Italian.", |
|
"ar": "The text is in Arabic.", |
|
"zh": "The text is in Chinese.", |
|
"th": "The text is in Thai.", |
|
"tr": "The text is in Turkish.", |
|
"pa": "The text is in Punjabi.", |
|
"ps": "The text is in Pashto.", |
|
"ja": "The text is in Japanese." |
|
} |
|
|
|
st.write(language_notes.get(language_code, "The text is in the selected language.")) |
|
|