Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| import json | |
| 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') | |
| theme = gr.themes.Base() | |
| with gr.Blocks(theme=theme) as demo: | |
| # with gr.Row(): | |
| # collection_name = gr.components.Textbox( | |
| # label='Document name') | |
| 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') | |
| submit_button = gr.components.Button(value='Submit', variant='primary') | |
| clear = gr.ClearButton([msg, chatbot]) | |
| upload.click(create_indexes, [file], [label]) | |
| with gr.Row(): | |
| # ... Other components ... | |
| source_document_textbox = gr.components.Textbox( | |
| label='Source Document', | |
| type='text', | |
| default='', | |
| lines=10, # Set the number of lines to display multiple documents | |
| ) | |
| submit_button.click(create_conversation, [msg, chatbot], [msg, chatbot, source_document_textbox]) | |
| msg.submit(create_conversation, [msg, chatbot], [msg, chatbot, source_document_textbox]) | |
| demo.launch() | |
| # # 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) | |