import streamlit as st import google.generativeai as genai import os from dotenv import load_dotenv import requests load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) model = genai.GenerativeModel("gemini-1.5-pro-latest") prompt = """ Input Text: {tamil_text} (Tanglish) Task: 1. Translate the input text to English. 2. Identify and explain grammatical errors. 3. Explain word choice and provide synonyms. give me the output in this format: 1. English Translation: The user input translated into grammatically correct English. 2. Grammar Explanation: A clear explanation of any grammatical errors in the user input (Tanglish) and suggestions for correction in Tamil. 3. Word Choice Explanation and Synonyms: Explanation of vocabulary meaning and synonyms in both English and Tamil. """ prompt_1 = """ You are an English teacher. Please understand the following Tanglish query and provide a correct English sentence with correct grammar: input: Tanglish query: {tamil_text} example input 1: epdi amma kita pasikidhu nu english la soldradhu example Output 1: mom, i am hungry example input 2: teacher kita bathroom poonu tu epdi kekuradhu example Output 2: Excuse me, teacher. May I please be excused to use the restroom? note output must in one line """ def generate_response(input_text, prompt): query = prompt.format(tamil_text=input_text) response = model.generate_content(query) response = response.text return st.markdown(response) def txt2speech(text): API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits" api_token = os.getenv('HUGGING_FACE') headers = {"Authorization": f"Bearer {api_token}"} payloads = {'inputs': text} response = requests.post(API_URL, headers=headers, json=payloads) with open('audio_answer.mp3', 'wb') as file: file.write(response.content) st.title("English Teaching AI") user_query = st.text_area("Type Tamil or Tanglish sentance") submit = st.button("Analyze") if submit: with st.spinner("Processing..."): answer = generate_response(user_query, prompt_1) txt2speech(answer) st.audio("audio_answer.mp3") with st.spinner("Analyzing..."): generate_response(user_query, prompt)