1
+ from src .pipelines .pipeline import CompletePipeline
2
+ from pywebio .platform .flask import start_server
3
+ from src .utils .functions import getConfig
4
+ from pywebio .output import *
5
+ from pywebio .input import *
6
+
7
+ def main ():
8
+ """
9
+ Main function to run the application, handle user inputs, and interact with the pipeline.
10
+
11
+ This function facilitates file uploads, processes user queries, and displays responses
12
+ using the CompletePipeline. The application continues to run until the user inputs "exit".
13
+ """
14
+ pipeline = CompletePipeline ()
15
+
16
+ inputData = input_group ("Data Upload" ,
17
+ inputs = [
18
+ file_upload (name = "files" , label = "Upload Files" , accept = ".csv" , multiple = True , placeholder = "Drop your CSV files here" ),
19
+ file_upload (name = "metadata" , label = "Upload Metadata" , accept = ".json" , multiple = False , placeholder = "Drop your metadata.json here" ),
20
+ input (name = "domain" , label = "Enter the Domain of your dataset" )
21
+ ])
22
+
23
+ pipeline .loadData (inputData = inputData ["files" ], metadata = inputData ["metadata" ]["content" ], domainContext = inputData ["domain" ])
24
+
25
+ while True :
26
+ question = input (label = "Enter your question" )
27
+ if question == "exit" :
28
+ break
29
+ else :
30
+ with put_loading ().style ("position: absolute; left: 50%" ):
31
+ flag = 0
32
+ for i in range (5 ):
33
+ try :
34
+ filename , code = pipeline .generateGraph (query = question )
35
+ except :
36
+ continue
37
+ message = pipeline .pythonRepl .run (code )
38
+ if message == "" :
39
+ flag = 1
40
+ break
41
+ else :
42
+ pass
43
+
44
+ if flag == 0 :
45
+ put_table ([
46
+ ["Query: " , question ],
47
+ ["Response: " , put_text (f"Encountered error in 5 tries, says: { message } " )]
48
+ ])
49
+ else :
50
+ put_table ([
51
+ ["Query: " , question ],
52
+ ["Response: " , put_html (open (filename , "r" ).read ())]
53
+ ])
54
+
55
+ if __name__ == "__main__" :
56
+ config = getConfig ("config.ini" )
57
+ start_server (main , port = config .getint ("APPLICATION" , "port" ), host = config .get ("APPLICATION" , "host" ))
0 commit comments