import gradio as gr import os from indexes import create_indexes #,clear_indexes from conversation import create_conversation from dotenv import load_dotenv load_dotenv() openai_api_key=os.getenv('OPENAI_API_KEY') with gr.Blocks() as demo: with gr.Row(): collection_name = gr.components.Textbox( label='Document name') # pinecone_environment = gr.components.Textbox( # label='Pinecone environment') # pinecone_index_name = gr.components.Textbox( # label='Pinecone index name') # openai_api_key = gr.components.Textbox( # label='Openai API key', type='password') with gr.Row(): with gr.Column(): file = gr.components.File( label='Upload your pdf file', file_count='single', file_types=['.pdf']) with gr.Row(): upload = gr.components.Button( value='Upload', variant='primary') label = gr.components.Textbox(label='Status of uploaded file') chatbot = gr.Chatbot(label='Talk to the Document') msg = gr.Textbox(label='Ask a question') clear = gr.ClearButton([msg, chatbot]) upload.click(create_indexes, [ file,collection_name], [label]) # index_clear_btn.click(clear_indexes, [ # pinecone_api_key, pinecone_environment, pinecone_index_name], [label, file]) msg.submit(create_conversation, [msg, chatbot, collection_name], [msg, chatbot]) # def same_auth((username, password)): # username: ('LawGPT0','') # password: ('GPT089!') # return username == password # Retrieve the serialized list of username and password pairs from environment variable credentials_json = os.environ.get("CREDENTIALS") if credentials_json is None: print("Error: Please set the CREDENTIALS environment variable with a JSON representation of the username and password pairs.") else: # Parse the JSON string into a list of tuples credentials = json.loads(credentials_json) demo.launch(auth=credentials) #if __name__ == '__main__': #demo.launch(auth=[("admin", "pa"),("razzan", "rosli")])