Dharma20 commited on
Commit
1d76bdf
Β·
verified Β·
1 Parent(s): e080cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -155
app.py CHANGED
@@ -1,155 +1,155 @@
1
- import gradio as gr
2
- from setup import *
3
- import pandas as pd
4
- from openpyxl import Workbook
5
- from openpyxl.utils.dataframe import dataframe_to_rows
6
- from openpyxl.styles import Font
7
- from agents import research_agent
8
- from vectorstore import extract_urls, urls_classify_list, clean_and_extract_html_data
9
- from usecase_agent import usecase_agent_func, vectorstore_writing
10
- # from feasibility_agent import feasibility_agent_func
11
-
12
-
13
-
14
- # # Function to create Excel file
15
- # def create_excel(df):
16
- # # Create a new Excel workbook and select the active sheet
17
- # wb = Workbook()
18
- # ws = wb.active
19
- # ws.title = "Use Cases"
20
-
21
- # # Define and write headers to the Excel sheet
22
- # headers = ['Use Case', 'Description', 'URLs']
23
- # ws.append(headers)
24
-
25
- # # Write data rows
26
- # for _, row in df.iterrows():
27
- # try:
28
- # use_case = row['use_case']
29
- # description = row['description']
30
- # urls = row['urls_list']
31
-
32
- # ws.append([use_case, description, None]) # Add use case and description
33
- # if urls:
34
- # for url_index, url in enumerate(urls):
35
- # cell = ws.cell(row=ws.max_row, column=3) # URLs go into the third column
36
- # cell.value = url
37
- # cell.hyperlink = url
38
- # cell.font = Font(color="0000FF", underline="single")
39
-
40
- # # Add a new row for additional URLs
41
- # if url_index < len(urls) - 1:
42
- # ws.append([None, None, None])
43
- # except KeyError as e:
44
- # print(f"Missing key in DataFrame row: {e}")
45
- # except Exception as e:
46
- # print(f"Unexpected error while processing row: {e}")
47
-
48
- # excel_file_path = "GenAI_use_cases_feasibility.xlsx"
49
- # wb.save(excel_file_path)
50
- # return excel_file_path
51
-
52
-
53
- # # Function to handle the report and create the DataFrame
54
- # def pd_creation(report):
55
- # # Assuming feasibility_agent_func returns a dictionary
56
- # pd_dict = feasibility_agent_func(report)
57
-
58
- # # Check for expected keys in pd_dict before proceeding
59
- # required_columns = ['use_case', 'description', 'urls_list']
60
- # if not all(col in pd_dict for col in required_columns):
61
- # raise ValueError(f"Missing one or more expected columns: {required_columns}")
62
-
63
- # # Create the DataFrame from the dictionary
64
- # df = pd.DataFrame(pd_dict)
65
-
66
- # # Convert the dataframe to the format expected by Gradio (list of lists)
67
- # data = df.values.tolist() # This creates a list of lists from the dataframe
68
-
69
- # # Create the Excel file and return its path
70
- # excel_file_path = create_excel(df) # Create the Excel file and get its path
71
-
72
- # return data, excel_file_path # Return the formatted data and the Excel file path
73
-
74
- # Main function that handles the user query and generates the report
75
- def main(user_input):
76
- # Research Agent
77
- agentstate_result = research_agent(user_input)
78
-
79
- # Vector Store
80
- urls, content = extract_urls(agentstate_result)
81
- pdf_urls, html_urls = urls_classify_list(urls)
82
- html_docs = clean_and_extract_html_data(html_urls)
83
-
84
- # Writing vector store (not explicitly defined in your example)
85
- vectorstore_writing(html_docs)
86
-
87
- # Use-case agent
88
- company_name = agentstate_result['company']
89
- industry_name = agentstate_result['industry']
90
-
91
- if company_name:
92
- topic = f'GenAI Usecases in {company_name} and {industry_name} industry. Explore {company_name} GenAI applications, key offerings, strategic focus areas, competitors, and market share.'
93
- else:
94
- topic = f'GenAI Usecases in {industry_name}. Explore {industry_name} GenAI applications, trends, challenges, and opportunities.'
95
- max_analysts = 3
96
-
97
- report = usecase_agent_func(topic, max_analysts)
98
- # pd_dict, excel_file_path = pd_creation(report)
99
-
100
- # Save the report as a markdown file
101
- report_file_path = "generated_report.md"
102
- with open(report_file_path, "w") as f:
103
- f.write(report)
104
- # pd_dict, excel_file_path
105
- return report, report_file_path
106
-
107
- # Example queries
108
- examples = [
109
- "How is the retail industry leveraging AI and ML?",
110
- "AI applications in automotive manufacturing"
111
- ]
112
-
113
- # Creating the Gradio interface
114
- with gr.Blocks(theme=gr.themes.Soft(font=gr.themes.GoogleFont('Open Sans'))) as demo:
115
- # Header section
116
- gr.HTML("<center><h1>UseCaseGenie - Discover GenAI Use cases for your company and Industry! πŸ€–πŸ§‘β€πŸ³.</h1><center>")
117
- gr.Markdown("""#### This GenAI Assistant πŸ€– helps you discover and explore Generative AI use cases for your company and industry.
118
- You can download the generated use case report as a <b>Markdown file</b> to gain insights and explore relevant GenAI applications.
119
- ### <b>Steps:</b>
120
- 1. <b>Enter your query</b> regarding any company or industry.
121
- 2. <b>Click on the 'Submit' button</b> and wait for the GenAI assistant to generate the report.
122
- 3. <b>Download the generated report<b>
123
- 4. Explore the GenAI use cases and URLs for further analysis.
124
- """)
125
-
126
-
127
- # Input for the user query
128
- with gr.Row():
129
- user_input = gr.Textbox(label="Enter your Query", placeholder='Type_here...')
130
-
131
- # Examples to help users with inputs
132
- with gr.Row():
133
- gr.Examples(examples=examples, inputs=user_input)
134
-
135
- # Buttons for submitting and downloading
136
- with gr.Row():
137
- submit_button = gr.Button("Submit")
138
- clear_btn = gr.ClearButton([user_input], value='Clear')
139
-
140
- # File download buttons
141
- with gr.Row():
142
- # Create a downloadable markdown file
143
- download_report_button = gr.File(label="Usecases Report")
144
-
145
- # # Create a downloadable Excel file
146
- # download_excel_button = gr.File(label="Feasibility Excel File")
147
-
148
- # Display report in Markdown format
149
- with gr.Row():
150
- report_output = gr.Markdown()
151
-
152
- submit_button.click(main, inputs=[user_input], outputs=[report_output, download_report_button])
153
-
154
- # Run the interface
155
- demo.launch()
 
1
+ import gradio as gr
2
+ from setup import *
3
+ import pandas as pd
4
+ from openpyxl import Workbook
5
+ from openpyxl.utils.dataframe import dataframe_to_rows
6
+ from openpyxl.styles import Font
7
+ from agents import research_agent
8
+ from vectorstore import extract_urls, urls_classify_list, clean_and_extract_html_data
9
+ from usecase_agent import usecase_agent_func, vectorstore_writing
10
+ # from feasibility_agent import feasibility_agent_func
11
+
12
+
13
+
14
+ # # Function to create Excel file
15
+ # def create_excel(df):
16
+ # # Create a new Excel workbook and select the active sheet
17
+ # wb = Workbook()
18
+ # ws = wb.active
19
+ # ws.title = "Use Cases"
20
+
21
+ # # Define and write headers to the Excel sheet
22
+ # headers = ['Use Case', 'Description', 'URLs']
23
+ # ws.append(headers)
24
+
25
+ # # Write data rows
26
+ # for _, row in df.iterrows():
27
+ # try:
28
+ # use_case = row['use_case']
29
+ # description = row['description']
30
+ # urls = row['urls_list']
31
+
32
+ # ws.append([use_case, description, None]) # Add use case and description
33
+ # if urls:
34
+ # for url_index, url in enumerate(urls):
35
+ # cell = ws.cell(row=ws.max_row, column=3) # URLs go into the third column
36
+ # cell.value = url
37
+ # cell.hyperlink = url
38
+ # cell.font = Font(color="0000FF", underline="single")
39
+
40
+ # # Add a new row for additional URLs
41
+ # if url_index < len(urls) - 1:
42
+ # ws.append([None, None, None])
43
+ # except KeyError as e:
44
+ # print(f"Missing key in DataFrame row: {e}")
45
+ # except Exception as e:
46
+ # print(f"Unexpected error while processing row: {e}")
47
+
48
+ # excel_file_path = "GenAI_use_cases_feasibility.xlsx"
49
+ # wb.save(excel_file_path)
50
+ # return excel_file_path
51
+
52
+
53
+ # # Function to handle the report and create the DataFrame
54
+ # def pd_creation(report):
55
+ # # Assuming feasibility_agent_func returns a dictionary
56
+ # pd_dict = feasibility_agent_func(report)
57
+
58
+ # # Check for expected keys in pd_dict before proceeding
59
+ # required_columns = ['use_case', 'description', 'urls_list']
60
+ # if not all(col in pd_dict for col in required_columns):
61
+ # raise ValueError(f"Missing one or more expected columns: {required_columns}")
62
+
63
+ # # Create the DataFrame from the dictionary
64
+ # df = pd.DataFrame(pd_dict)
65
+
66
+ # # Convert the dataframe to the format expected by Gradio (list of lists)
67
+ # data = df.values.tolist() # This creates a list of lists from the dataframe
68
+
69
+ # # Create the Excel file and return its path
70
+ # excel_file_path = create_excel(df) # Create the Excel file and get its path
71
+
72
+ # return data, excel_file_path # Return the formatted data and the Excel file path
73
+
74
+ # Main function that handles the user query and generates the report
75
+ def main(user_input):
76
+ # Research Agent
77
+ agentstate_result = research_agent(user_input)
78
+
79
+ # Vector Store
80
+ urls, content = extract_urls(agentstate_result)
81
+ pdf_urls, html_urls = urls_classify_list(urls)
82
+ html_docs = clean_and_extract_html_data(html_urls)
83
+
84
+ # Writing vector store (not explicitly defined in your example)
85
+ vectorstore_writing(html_docs)
86
+
87
+ # Use-case agent
88
+ company_name = agentstate_result['company']
89
+ industry_name = agentstate_result['industry']
90
+
91
+ if company_name:
92
+ topic = f'GenAI Usecases in {company_name} and {industry_name} industry. Explore {company_name} GenAI applications, key offerings, strategic focus areas, competitors, and market share.'
93
+ else:
94
+ topic = f'GenAI Usecases in {industry_name}. Explore {industry_name} GenAI applications, trends, challenges, and opportunities.'
95
+ max_analysts = 3
96
+
97
+ report = usecase_agent_func(topic, max_analysts)
98
+ # pd_dict, excel_file_path = pd_creation(report)
99
+
100
+ # Save the report as a markdown file
101
+ report_file_path = "generated_report.md"
102
+ with open(report_file_path, "w") as f:
103
+ f.write(report)
104
+ # pd_dict, excel_file_path
105
+ return report, report_file_path
106
+
107
+ # Example queries
108
+ examples = [
109
+ "How is the retail industry leveraging AI and ML?",
110
+ "AI applications in automotive manufacturing"
111
+ ]
112
+
113
+ # Creating the Gradio interface
114
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
115
+ # Header section
116
+ gr.HTML("<center><h1>UseCaseGenie - Discover GenAI Use cases for your company and Industry! πŸ€–πŸ§‘β€πŸ³.</h1><center>")
117
+ gr.Markdown("""#### This GenAI Assistant πŸ€– helps you discover and explore Generative AI use cases for your company and industry.
118
+ You can download the generated use case report as a <b>Markdown file</b> to gain insights and explore relevant GenAI applications.
119
+ ### <b>Steps:</b>
120
+ 1. <b>Enter your query</b> regarding any company or industry.
121
+ 2. <b>Click on the 'Submit' button</b> and wait for the GenAI assistant to generate the report.
122
+ 3. <b>Download the generated report<b>
123
+ 4. Explore the GenAI use cases and URLs for further analysis.
124
+ """)
125
+
126
+
127
+ # Input for the user query
128
+ with gr.Row():
129
+ user_input = gr.Textbox(label="Enter your Query", placeholder='Type_here...')
130
+
131
+ # Examples to help users with inputs
132
+ with gr.Row():
133
+ gr.Examples(examples=examples, inputs=user_input)
134
+
135
+ # Buttons for submitting and downloading
136
+ with gr.Row():
137
+ submit_button = gr.Button("Submit")
138
+ clear_btn = gr.ClearButton([user_input], value='Clear')
139
+
140
+ # File download buttons
141
+ with gr.Row():
142
+ # Create a downloadable markdown file
143
+ download_report_button = gr.File(label="Usecases Report")
144
+
145
+ # # Create a downloadable Excel file
146
+ # download_excel_button = gr.File(label="Feasibility Excel File")
147
+
148
+ # Display report in Markdown format
149
+ with gr.Row():
150
+ report_output = gr.Markdown()
151
+
152
+ submit_button.click(main, inputs=[user_input], outputs=[report_output, download_report_button])
153
+
154
+ # Run the interface
155
+ demo.launch()