Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from groq import Groq
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# β
Load Groq API key from Hugging Face Secrets
|
| 6 |
+
api_key = os.getenv("apikey")
|
| 7 |
+
client = Groq(api_key=api_key)
|
| 8 |
+
|
| 9 |
+
# π Supported Languages
|
| 10 |
+
LANGUAGES = {
|
| 11 |
+
"French": "French",
|
| 12 |
+
"Spanish": "Spanish",
|
| 13 |
+
"Urdu": "Urdu",
|
| 14 |
+
"German": "German",
|
| 15 |
+
"Chinese": "Chinese",
|
| 16 |
+
"Arabic": "Arabic",
|
| 17 |
+
"Turkish": "Turkish",
|
| 18 |
+
"Russian": "Russian",
|
| 19 |
+
"Japanese": "Japanese",
|
| 20 |
+
"Korean": "Korean"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# β
Streamlit App UI
|
| 24 |
+
st.set_page_config(page_title="π Translation App", layout="centered")
|
| 25 |
+
st.title("π English to Any Language Translator")
|
| 26 |
+
st.markdown("π Powered by **Groq LLaMA 3.3 70B**")
|
| 27 |
+
|
| 28 |
+
text = st.text_area("βοΈ Enter English text:")
|
| 29 |
+
target_lang = st.selectbox("π Choose target language:", list(LANGUAGES.keys()))
|
| 30 |
+
|
| 31 |
+
if st.button("Translate"):
|
| 32 |
+
if not text.strip():
|
| 33 |
+
st.warning("Please enter some English text.")
|
| 34 |
+
else:
|
| 35 |
+
prompt = f"Translate the following English sentence to {LANGUAGES[target_lang]}:\n\n'{text}'\n\nTranslation:"
|
| 36 |
+
try:
|
| 37 |
+
response = client.chat.completions.create(
|
| 38 |
+
messages=[{"role": "user", "content": prompt}],
|
| 39 |
+
model="llama3-70b-8192"
|
| 40 |
+
)
|
| 41 |
+
translation = response.choices[0].message.content.strip()
|
| 42 |
+
st.success("β
Translation completed!")
|
| 43 |
+
st.markdown(f"**π Translated Text ({LANGUAGES[target_lang]}):**")
|
| 44 |
+
st.markdown(f"> {translation}")
|
| 45 |
+
except Exception as e:
|
| 46 |
+
st.error(f"β Error: {e}")
|
| 47 |
+
|
| 48 |
+
st.markdown("---")
|
| 49 |
+
st.caption("Made with β€οΈ by Maheen Touqeer")
|