File size: 3,158 Bytes
ccd9997
 
 
 
3e57f59
ccd9997
 
 
 
 
 
 
 
3e57f59
ccd9997
10ab54d
3e57f59
 
 
 
 
 
 
 
 
 
 
 
10ab54d
 
 
 
3e57f59
 
 
ccd9997
 
 
 
d650903
ccd9997
 
 
3e57f59
 
 
 
10ab54d
 
3e57f59
 
ccd9997
 
3e57f59
 
ccd9997
 
 
 
3e57f59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10ab54d
 
 
 
3e57f59
d650903
3e57f59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

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."))