File size: 2,015 Bytes
df262b6
71c240e
255e97c
71c240e
df262b6
71c240e
 
 
 
02eb8d3
df262b6
02eb8d3
d7024a0
 
 
c560874
df262b6
 
 
 
 
 
 
 
 
 
 
 
 
e779338
df262b6
 
d7024a0
c560874
 
 
 
 
 
 
 
 
d7024a0
 
08463bd
7b3226e
0549b59
 
 
 
 
 
 
 
 
403dd0c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)