import os from groq import Groq from gtts import gTTS import streamlit as st # Set your Groq API Key as an environment variable (replace with your actual API key) os.environ["GROQ_API_KEY"] = "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" # Replace with your actual API key # Initialize Groq client with the API key from the environment api_key = os.environ.get("GROQ_API_KEY") client = Groq(api_key=api_key) # Function to generate "Happy New Year" text in the selected language using Groq API def generate_happy_new_year(language_code): # For the additional languages, return the correct translation directly 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") # Function for Text-to-Speech in Different Languages 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" # Save the audio in the /tmp folder tts.save(audio_path) return audio_path # Streamlit UI st.title("Happy New Year in Multiple Languages") st.write("Select a language to generate 'Happy New Year' text and hear it!") # Language selection - Added Punjabi (pa), Pashto (ps), and Japanese (ja) language_code = st.selectbox("Choose a Language", ["en", "ur", "hi", "bn", "es", "fr", "de", "it", "ar", "zh", "th", "tr", "pa", "ps", "ja"]) # Generate and play "Happy New Year" in the selected language happy_new_year_text = generate_happy_new_year(language_code) # Display the generated text visually on the app st.write(f"Generated Text in {language_code.upper()}: {happy_new_year_text}") # Convert text to speech and play the audio audio_file = text_to_speech(happy_new_year_text, language_code) # Display the audio player in Streamlit st.audio(audio_file, format="audio/mp3") # Add a note about the language being spoken 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."))