Dharma20 commited on
Commit
e21bb58
Β·
verified Β·
1 Parent(s): f2a41d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +154 -154
app.py CHANGED
@@ -1,154 +1,154 @@
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
- # Create the DataFrame from the dictionary
59
- df = pd.DataFrame(pd_dict)
60
-
61
- # Convert the dataframe to the format expected by Gradio (list of lists)
62
- data = df.values.tolist() # This creates a list of lists from the dataframe
63
-
64
- # Create the Excel file and return its path
65
- excel_file_path = create_excel(df) # Create the Excel file and get its path
66
-
67
- return data, excel_file_path # Return the formatted data and the Excel file path
68
-
69
-
70
- # Main function that handles the user query and generates the report
71
- def main(user_input):
72
- # Research Agent
73
- agentstate_result = research_agent(user_input)
74
-
75
- # Vector Store
76
- urls, content = extract_urls(agentstate_result)
77
- pdf_urls, html_urls = urls_classify_list(urls)
78
- html_docs = clean_and_extract_html_data(html_urls)
79
-
80
- # Writing vector store (not explicitly defined in your example)
81
- vectorstore_writing(html_docs)
82
-
83
- # Use-case agent
84
- company_name = agentstate_result['company']
85
- industry_name = agentstate_result['industry']
86
-
87
- if company_name:
88
- 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.'
89
- else:
90
- topic = f'GenAI Usecases in {industry_name}. Explore {industry_name} GenAI applications, trends, challenges, and opportunities.'
91
- max_analysts = 3
92
-
93
- report = usecase_agent_func(topic, max_analysts)
94
- pd_dict, excel_file_path = pd_creation(report)
95
-
96
- # Save the report as a markdown file
97
- report_file_path = "generated_report.md"
98
- with open(report_file_path, "w") as f:
99
- f.write(report)
100
-
101
- return report, report_file_path , excel_file_path
102
-
103
-
104
- # Example queries
105
- examples = [
106
- "AI in healthcare industry",
107
- "How is the retail industry leveraging AI and ML?",
108
- "AI applications in automotive manufacturing"
109
- ]
110
-
111
-
112
- # Creating the Gradio interface
113
- with gr.Blocks(theme=gr.themes.Soft(font=gr.themes.GoogleFont('Open Sans'))) as demo:
114
- # Header section
115
- gr.HTML("<center><h1>UseCaseGenie - Discover GenAI Use cases for your company and Industry! πŸ€–πŸ§‘β€πŸ³.</h1><center>")
116
- gr.Markdown("""#### This GenAI Assistant πŸ€– helps you discover and explore Generative AI use cases for your company and industry.
117
- You can download the generated use case report as a <b>Markdown file</b> to gain insights and explore relevant GenAI applications.
118
- ### <b>Steps:</b>
119
- 1. <b>Enter your query</b> regarding any company or industry.
120
- 2. <b>Click on the 'Submit' button</b> and wait for the GenAI assistant to generate the report.
121
- 3. <b>Download the generated report<b>
122
- 4. Explore the GenAI use cases and URLs for further analysis.
123
- """)
124
-
125
-
126
- # Input for the user query
127
- with gr.Row():
128
- user_input = gr.Textbox(label="Enter your Query", placeholder='Type_here...')
129
-
130
- # Examples to help users with inputs
131
- with gr.Row():
132
- gr.Examples(examples=examples, inputs=user_input)
133
-
134
- # Buttons for submitting and downloading
135
- with gr.Row():
136
- submit_button = gr.Button("Submit")
137
- clear_btn = gr.ClearButton([user_input], value='Clear')
138
-
139
- # File download buttons
140
- with gr.Row():
141
- # Create a downloadable markdown file
142
- download_report_button = gr.File(label="Usecases Report")
143
-
144
- # Create a downloadable Excel file
145
- download_excel_button = gr.File(label="Feasibility Excel File")
146
-
147
- # Display report in Markdown format
148
- with gr.Row():
149
- report_output = gr.Markdown()
150
-
151
- submit_button.click(main, inputs=[user_input], outputs=[report_output, download_report_button,download_excel_button])
152
-
153
- # Run the interface
154
- 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
+ # Create the DataFrame from the dictionary
59
+ df = pd.DataFrame(pd_dict)
60
+
61
+ # Convert the dataframe to the format expected by Gradio (list of lists)
62
+ data = df.values.tolist() # This creates a list of lists from the dataframe
63
+
64
+ # Create the Excel file and return its path
65
+ excel_file_path = create_excel(df) # Create the Excel file and get its path
66
+
67
+ return data, excel_file_path # Return the formatted data and the Excel file path
68
+
69
+
70
+ # Main function that handles the user query and generates the report
71
+ def main(user_input):
72
+ # Research Agent
73
+ agentstate_result = research_agent(user_input)
74
+
75
+ # Vector Store
76
+ urls, content = extract_urls(agentstate_result)
77
+ pdf_urls, html_urls = urls_classify_list(urls)
78
+ html_docs = clean_and_extract_html_data(html_urls)
79
+
80
+ # Writing vector store (not explicitly defined in your example)
81
+ vectorstore_writing(html_docs)
82
+
83
+ # Use-case agent
84
+ company_name = agentstate_result['company']
85
+ industry_name = agentstate_result['industry']
86
+
87
+ if company_name:
88
+ 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.'
89
+ else:
90
+ topic = f'GenAI Usecases in {industry_name}. Explore {industry_name} GenAI applications, trends, challenges, and opportunities.'
91
+ max_analysts = 3
92
+
93
+ report = usecase_agent_func(topic, max_analysts)
94
+ pd_dict, excel_file_path = pd_creation(report)
95
+
96
+ # Save the report as a markdown file
97
+ report_file_path = "generated_report.md"
98
+ with open(report_file_path, "w") as f:
99
+ f.write(report)
100
+
101
+ return report, report_file_path , excel_file_path
102
+
103
+
104
+ # Example queries
105
+ examples = [
106
+ "AI in healthcare industry",
107
+ "How is the retail industry leveraging AI and ML?",
108
+ "AI applications in automotive manufacturing"
109
+ ]
110
+
111
+
112
+ # Creating the Gradio interface
113
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
114
+ # Header section
115
+ gr.HTML("<center><h1>UseCaseGenie - Discover GenAI Use cases for your company and Industry! πŸ€–πŸ§‘β€πŸ³.</h1><center>")
116
+ gr.Markdown("""#### This GenAI Assistant πŸ€– helps you discover and explore Generative AI use cases for your company and industry.
117
+ You can download the generated use case report as a <b>Markdown file</b> to gain insights and explore relevant GenAI applications.
118
+ ### <b>Steps:</b>
119
+ 1. <b>Enter your query</b> regarding any company or industry.
120
+ 2. <b>Click on the 'Submit' button</b> and wait for the GenAI assistant to generate the report.
121
+ 3. <b>Download the generated report<b>
122
+ 4. Explore the GenAI use cases and URLs for further analysis.
123
+ """)
124
+
125
+
126
+ # Input for the user query
127
+ with gr.Row():
128
+ user_input = gr.Textbox(label="Enter your Query", placeholder='Type_here...')
129
+
130
+ # Examples to help users with inputs
131
+ with gr.Row():
132
+ gr.Examples(examples=examples, inputs=user_input)
133
+
134
+ # Buttons for submitting and downloading
135
+ with gr.Row():
136
+ submit_button = gr.Button("Submit")
137
+ clear_btn = gr.ClearButton([user_input], value='Clear')
138
+
139
+ # File download buttons
140
+ with gr.Row():
141
+ # Create a downloadable markdown file
142
+ download_report_button = gr.File(label="Usecases Report")
143
+
144
+ # Create a downloadable Excel file
145
+ download_excel_button = gr.File(label="Feasibility Excel File")
146
+
147
+ # Display report in Markdown format
148
+ with gr.Row():
149
+ report_output = gr.Markdown()
150
+
151
+ submit_button.click(main, inputs=[user_input], outputs=[report_output, download_report_button,download_excel_button])
152
+
153
+ # Run the interface
154
+ demo.launch()