Spaces:
Sleeping
Sleeping
Delete app.py
#2
by billo2024 - opened
app.py
DELETED
|
@@ -1,43 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import groq
|
| 4 |
-
|
| 5 |
-
# Get API key from environment variable
|
| 6 |
-
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 7 |
-
|
| 8 |
-
client = groq.Groq(api_key=GROQ_API_KEY)
|
| 9 |
-
|
| 10 |
-
def translate_text(text, target_language):
|
| 11 |
-
prompt = (
|
| 12 |
-
f"Translate the following English text into {target_language}:\n\n"
|
| 13 |
-
f"\"{text}\"\n\n"
|
| 14 |
-
f"Only provide the translated text in {target_language}, without explanation."
|
| 15 |
-
)
|
| 16 |
-
try:
|
| 17 |
-
response = client.chat.completions.create(
|
| 18 |
-
model="llama3-70b-8192",
|
| 19 |
-
messages=[{"role": "user", "content": prompt}],
|
| 20 |
-
temperature=0.3,
|
| 21 |
-
max_tokens=300,
|
| 22 |
-
)
|
| 23 |
-
return response.choices[0].message.content.strip()
|
| 24 |
-
except Exception as e:
|
| 25 |
-
return f"❌ Error: {str(e)}"
|
| 26 |
-
|
| 27 |
-
def translate_interface(text, language):
|
| 28 |
-
if not text or not language:
|
| 29 |
-
return "Please enter both text and target language."
|
| 30 |
-
return translate_text(text, language)
|
| 31 |
-
|
| 32 |
-
iface = gr.Interface(
|
| 33 |
-
fn=translate_interface,
|
| 34 |
-
inputs=[
|
| 35 |
-
gr.Textbox(label="Enter English Text", lines=4, placeholder="Type English sentence here..."),
|
| 36 |
-
gr.Textbox(label="Target Language", placeholder="e.g. French, Hindi, Arabic")
|
| 37 |
-
],
|
| 38 |
-
outputs="text",
|
| 39 |
-
title="🌍 English to Any Language Translator (GROQ + LLaMA 3)",
|
| 40 |
-
description="Translate English text into any desired language using GROQ's LLaMA 3 model."
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|