initial commit
Browse files- Language-Translator-Assistant.py +53 -0
- requirements.txt +4 -0
Language-Translator-Assistant.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from google import genai
|
| 3 |
+
from google.genai import types
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 10 |
+
|
| 11 |
+
client = genai.Client(api_key=GEMINI_API_KEY)
|
| 12 |
+
|
| 13 |
+
languages = {
|
| 14 |
+
"Hindi": "Translate the given sentence into Hindi.",
|
| 15 |
+
"Telugu": "Translate the given sentence into Telugu.",
|
| 16 |
+
"French": "Translate the given sentence into French."
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def language_translator(question, language):
|
| 20 |
+
system_prompt = languages[language]
|
| 21 |
+
|
| 22 |
+
response = client.models.generate_content(
|
| 23 |
+
model="gemini-2.5-flash",
|
| 24 |
+
config=types.GenerateContentConfig(
|
| 25 |
+
system_instruction=system_prompt,
|
| 26 |
+
temperature=0.3,
|
| 27 |
+
max_output_tokens=2000
|
| 28 |
+
),
|
| 29 |
+
contents=question
|
| 30 |
+
)
|
| 31 |
+
return response.text
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
demo = gr.Interface(
|
| 35 |
+
fn=language_translator,
|
| 36 |
+
inputs=[
|
| 37 |
+
gr.Textbox(
|
| 38 |
+
lines=3,
|
| 39 |
+
placeholder="Enter a sentence to translate...",
|
| 40 |
+
label="Input Sentence"
|
| 41 |
+
),
|
| 42 |
+
gr.Dropdown(
|
| 43 |
+
choices=list(languages.keys()),
|
| 44 |
+
value="Hindi",
|
| 45 |
+
label="Target Language"
|
| 46 |
+
)
|
| 47 |
+
],
|
| 48 |
+
outputs=gr.Textbox(lines=5, label="Translated Output"),
|
| 49 |
+
title="Language Translator",
|
| 50 |
+
description="Translate a sentence into Hindi, Telugu, or French using Gemini."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
google-genai
|
| 2 |
+
dotenv
|
| 3 |
+
groq
|
| 4 |
+
gradio
|