import uvicorn import streamlit as st from multiprocessing import Process import socket import time import audiobot import chatbot import os def run_st_app(): st.set_page_config( page_title='Welcome to Visual Question Answering - Bot', page_icon=':robot:', layout='wide' ) st.sidebar.title('VQA Bot') st.sidebar.write(''' VQA Bot addresses the challenge of visual question answering with the chat and voice assistance. Here, we merged ViLT(Vision-and-Language Transformer) model fine-tuned on VQAv2 into T5-small (Text-to-Text Transfer Transformer). We pretrained and finetuned our model on Language transformer to get the desired result. Please use the radio buttons below to navigate. ''') selected_page = st.sidebar.radio('Go to', ('VQA Chatbot', 'VQA Audiobot')) if selected_page == 'VQA Chatbot': chatbot.show() elif selected_page == 'VQA Audiobot': audiobot.show() st.caption( 'Created by Madhuri Sakhare - [Github](https://github.com/msak1612/vqa_chatbot) [Linkedin](https://www.linkedin.com/in/madhuri-sakhare/)') def run_uvicorn(): os.system('uvicorn server:app --port 8080 --host 0.0.0.0 --workers 1') def start_server(): if not is_port_in_use(8080): with st.spinner(text='Loading models...'): proc = Process(target=run_uvicorn, args=(), daemon=True) proc.start() while not is_port_in_use(8080): time.sleep(1) st.success('Models are loaded.') def is_port_in_use(port): # Find whether port is available using https://stackoverflow.com/questions/2470971/fast-way-to-test-if-a-port-is-in-use-using-python with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: return s.connect_ex(('0.0.0.0', port)) == 0 if __name__ == '__main__': run_st_app() if 'server' not in st.session_state: st.session_state['server'] = True start_server()