Mr-Vicky-01 commited on
Commit
f6efa8c
1 Parent(s): 6c38952

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -4
app.py CHANGED
@@ -1,24 +1,68 @@
1
  import streamlit as st
2
  import google.generativeai as genai
3
  import os
 
 
 
4
 
5
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
6
 
7
  model = genai.GenerativeModel("gemini-1.5-pro-latest")
8
  prompt = """
9
- you are a english teacher.so, understand the following Tanglish query and give a correct English sentance with proper grammar:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  Tanglish query: {tamil_text}
 
 
 
 
 
 
 
 
11
  """
12
 
13
- def generate_response(input_text):
14
  query = prompt.format(tamil_text=input_text)
15
  response = model.generate_content(query)
16
  response = response.text
17
  return st.markdown(response)
18
 
19
- st.title("English Teaching Assistant")
 
 
 
 
 
 
 
 
 
 
 
 
20
  user_query = st.text_area("Type Tamil or Tanglish sentance")
21
  submit = st.button("Analyze")
22
  if submit:
23
  with st.spinner("Processing..."):
24
- generate_response(user_query)
 
 
 
 
 
1
  import streamlit as st
2
  import google.generativeai as genai
3
  import os
4
+ from dotenv import load_dotenv
5
+ import requests
6
+ load_dotenv()
7
 
8
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
 
10
  model = genai.GenerativeModel("gemini-1.5-pro-latest")
11
  prompt = """
12
+ Input Text: {tamil_text} (Tanglish)
13
+
14
+ Task:
15
+
16
+ 1. Translate the input text to English.
17
+ 2. Identify and explain grammatical errors.
18
+ 3. Explain word choice and provide synonyms.
19
+
20
+ give me the output in this format:
21
+
22
+ 1. English Translation: The user input translated into grammatically correct English.
23
+ 2. Grammar Explanation: A clear explanation of any grammatical errors in the user input (Tanglish) and suggestions for correction in Tamil.
24
+ 3. Word Choice Explanation and Synonyms: Explanation of vocabulary meaning and synonyms in both English and Tamil.
25
+ """
26
+
27
+ prompt_1 = """
28
+ You are an English teacher. Please understand the following Tanglish query and provide a correct English sentence with correct grammar:
29
+ input:
30
  Tanglish query: {tamil_text}
31
+
32
+ example input 1: epdi amma kita pasikidhu nu english la soldradhu
33
+ example Output 1: mom, i am hungry
34
+
35
+ example input 2: teacher kita bathroom poonu tu epdi kekuradhu
36
+ example Output 2: Excuse me, teacher. May I please be excused to use the restroom?
37
+
38
+ note output must in one line
39
  """
40
 
41
+ def generate_response(input_text, prompt):
42
  query = prompt.format(tamil_text=input_text)
43
  response = model.generate_content(query)
44
  response = response.text
45
  return st.markdown(response)
46
 
47
+ def txt2speech(text):
48
+ API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
49
+ api_token = os.getenv('HUGGING_FACE')
50
+ headers = {"Authorization": f"Bearer {api_token}"}
51
+ payloads = {'inputs': text}
52
+
53
+ response = requests.post(API_URL, headers=headers, json=payloads)
54
+
55
+ with open('audio_answer.mp3', 'wb') as file:
56
+ file.write(response.content)
57
+
58
+
59
+ st.title("English Teaching AI")
60
  user_query = st.text_area("Type Tamil or Tanglish sentance")
61
  submit = st.button("Analyze")
62
  if submit:
63
  with st.spinner("Processing..."):
64
+ answer = generate_response(user_query, prompt_1)
65
+ txt2speech(answer)
66
+ st.audio("audio_answer.mp3")
67
+ with st.spinner("Analyzing..."):
68
+ generate_response(user_query, prompt)