deepugaur commited on
Commit
ae2c826
·
verified ·
1 Parent(s): 441da5d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install transformers
2
+ !pip install torch
3
+ !pip install streamlit
4
+ !pip install SpeechRecognition
5
+ !pip install gtts
6
+
7
+ import streamlit as st # Make sure to import streamlit
8
+ import torch
9
+ from transformers import MarianMTModel, MarianTokenizer
10
+ import speech_recognition as sr
11
+ from gtts import gTTS
12
+ import os
13
+ import datetime
14
+
15
+ # Function definitions go here (as provided earlier)
16
+
17
+ # Set the time restriction
18
+ def is_allowed_time():
19
+ current_time = datetime.datetime.now().time()
20
+ if current_time >= datetime.time(18, 0): # After 6 PM IST
21
+ return True
22
+ else:
23
+ return False
24
+
25
+ # Streamlit app
26
+ st.title("English to Hindi Audio Translation")
27
+
28
+ if is_allowed_time():
29
+ audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
30
+ if audio_file is not None:
31
+ text = recognize_speech_from_file(audio_file)
32
+ st.write(f"Recognized English Text: {text}")
33
+ translated_text = translate_text(text)
34
+ st.write(f"Translated Hindi Text: {translated_text}")
35
+ audio_output = convert_to_audio(translated_text)
36
+ st.audio(audio_output, format='audio/mp3')
37
+ else:
38
+ st.write("Translation service is available after 6 PM IST.")