File size: 1,054 Bytes
4f3952b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
import google.generativeai as genai

app = Flask(__name__)

# Configure your Gemini API key
genai.configure(api_key = "AIzaSyBoEzi2YrxrGZ2WwqDRCDTG6rbdXTj9yMQ")

# Supported languages
languages = {
    "Hindi": "hi"
}

@app.route('/')
def index():
    return render_template('index.html', languages=languages)

@app.route('/translate', methods=['POST'])
def translate():
    data = request.get_json()
    text = data.get('text', '')
    target = data.get('target', '')
    try:
        model = genai.GenerativeModel('gemini-2.0-flash')
        prompt = f"Translate the following text {target} and  just provide  me translated text  in hindi  langauge   no  marks  should  be  there only plane text nothing else:\n{text}"
        response = model.generate_content(prompt)
        return jsonify({'translation': response.text})
    except Exception as e:
        return jsonify({'translation': f"Error: {e}"}), 500

if __name__ == '__main__':
    app.run(debug=True)