hey_rehan / app.py
muhammadnasar's picture
Upload 6 files
6cc9795 verified
raw
history blame contribute delete
No virus
4.68 kB
# from gpt_module import generate_response
# from dalle_module import generate_image
# from translation_module import translation_to_english
# from tts_module import text_to_speech
# from stt import transcribe_audio
# def main():
# print("Welcome to the ChatGPT CLI application!")
# while True:
# user_input = input("Enter command: ")
# if user_input.startswith('/imagine'):
# img = user_input.replace('/imagine', '').strip()
# print(generate_image(img))
# elif user_input.startswith('/chat'):
# prompt = user_input.replace('/chat', '').strip()
# print(generate_response(prompt))
# elif user_input.startswith('/translate'):
# tra = user_input.replace('/translate', '').strip()
# print(translation_to_english(tra))
# elif user_input.startswith('/voice'):
# text = user_input.replace('/voice', '').strip()
# print(text_to_speech(text))
# elif user_input.startswith('/transcribe'):
# print("Please upload the audio file.")
# audio_file = input("Enter the path to the audio file: ")
# print(transcribe_audio(audio_file))
# elif user_input.startswith('/help'):
# print_help()
# else:
# print("Unknown command. Type '/help' for a list of commands.")
# def print_help():
# help_text = """
# πŸ‘‰ To generate an image, type '/imagine <prompt>'
# πŸ‘‰ To chat with the model, type '/chat <prompt>'
# πŸ‘‰ To translate text to English, type '/translate <text>'
# πŸ‘‰ For Text to Speech, type '/voice <some text>'
# πŸ‘‰ To transcribe audio to text, type '/transcribe' and follow the prompts
# πŸ‘‰ For help, type '/help'
# """
# print(help_text)
# if __name__ == '__main__':
# main()
import streamlit as st
from gpt_module import generate_response
from dalle_module import generate_image
from translation_module import translation_to_english
from tts_module import text_to_speech
from stt import transcribe_audio
import os
def main():
st.sidebar.title("Hey Rehan Assistant")
user_input = st.sidebar.selectbox("Select command:", ["/imagine", "/chat", "/translate", "/voice", "/transcribe", "/help"])
if user_input == "/imagine":
st.subheader('Prompt To Image generation', divider='rainbow')
prompt = st.text_input("Enter prompt To Generate Image:")
if st.button("Generate Image"):
st.image(generate_image(prompt))
elif user_input == "/chat":
st.subheader('Hey Rehan AI Assistant', divider='rainbow')
prompt = st.text_input("Ask anything You want to know")
if st.button("Chat"):
response = generate_response(prompt)
st.success(response)
elif user_input == "/translate":
st.subheader('Translate Into English', divider='rainbow')
audio_file = st.file_uploader("Upload Audio File", type=["mp3", "wav"])
if audio_file is not None:
# st.audio(uploaded_file, format='audio/wav')
if st.button("Translate to English"):
result = translation_to_english(audio_file)
st.success(result)
elif user_input == "/voice":
st.subheader('Text to Speech', divider='rainbow')
text = st.text_input("Enter text for Text to Speech:")
if st.button("Convert to Speech"):
audio_bytes = text_to_speech(text)
st.audio(audio_bytes, format='audio/wav')
elif user_input == "/transcribe":
st.subheader('Audio to Text Transcription', divider='rainbow')
uploaded_file = st.file_uploader("Upload audio file", type=["mp3", "wav"])
if uploaded_file is not None:
if st.button("Transcribe Audio"):
with open("temp_audio_file.mp3", "wb") as f:
f.write(uploaded_file.getvalue())
transcription = transcribe_audio("temp_audio_file.mp3")
st.success(transcription)
os.remove("temp_audio_file.mp3")
elif user_input == "/help":
print_help()
def print_help():
help_text = """
πŸ‘‰ To generate an image, select '/imagine' and enter a prompt.
πŸ‘‰ To chat with the model, select '/chat' and enter a prompt.
πŸ‘‰ To translate text to English, select '/translate' and enter text.
πŸ‘‰ For Text to Speech, select '/voice' and enter some text.
πŸ‘‰ To transcribe audio to text, select '/transcribe' and upload the audio file.
πŸ‘‰ For help, select '/help'.
"""
st.write(help_text)
if __name__ == '__main__':
main()