File size: 2,559 Bytes
3394c04
 
 
f6efa8c
3394c04
 
 
561126d
 
b40dae0
fa75acc
dea5d58
f6efa8c
 
 
 
 
6c38952
f6efa8c
5682152
f6efa8c
 
 
 
 
63c6b19
 
 
 
 
ca71c26
d793670
3394c04
 
f6efa8c
3394c04
561126d
 
 
 
 
 
 
3394c04
b6bb993
3394c04
f6efa8c
 
 
 
 
 
 
 
 
 
 
 
8eff081
63c6b19
5682152
3394c04
 
8eff081
561126d
2f908e7
f6efa8c
8eff081
ed0d7fa
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import google.generativeai as genai
import os
import requests

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

# model = genai.GenerativeModel("gemini-1.5-pro-latest")

prompt = """
you are a english teacher.so, understand the following Tanglish query and give a correct English sentance with proper grammar and explain the how tanglish query converts into english, like a english teacher:
Tanglish query: {tamil_text}
"""

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: amma kita pasikidhu nu english la epdi sollanum?
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?

example input 3: naaliku veliya engayaachi poolama nu english la epdi sollanum?
example Output 3: Can we go out somewhere tomorrow?

example input 4: park ku pooga english la epdi vazhi kekuradhu?
example Output 4: how do I ask directions for the park.

note: output must in one line
"""

def generate_response(input_text, prompt):
  query = prompt.format(tamil_text=input_text)
  model = genai.GenerativeModel("gemini-1.5-pro-latest")
  response = model.generate_content(query)
  return response.text

def voice_response(input_text, prompt):
  query = prompt.format(tamil_text=input_text)
  model = genai.GenerativeModel("gemini-1.5-flash-latest")
  response = model.generate_content(query)
  return response.text

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")
example_text = "park ku pooga english la epdi vazhi kekuradhu?"
user_query = st.text_area("Type Tamil or Tanglish sentance", value=example_text)
submit = st.button("Analyze")
if submit:
    with st.spinner("### 🤖Processing..."):
        answer = voice_response(user_query, prompt_1)
        txt2speech(f"In English: You can say, {answer}")
        st.audio("audio_answer.mp3")
    with st.spinner("### 🤖Analyzing your Query..."):
        response = generate_response(user_query, prompt)
        st.markdown(response)