Spaces:
Running
Running
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" | |
} | |
def index(): | |
return render_template('index.html', languages=languages) | |
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) |