|
import gradio as gr |
|
from setup import * |
|
import pandas as pd |
|
from openpyxl import Workbook |
|
from openpyxl.utils.dataframe import dataframe_to_rows |
|
from openpyxl.styles import Font |
|
from agents import research_agent |
|
from vectorstore import extract_urls, urls_classify_list, clean_and_extract_html_data |
|
from usecase_agent import usecase_agent_func, vectorstore_writing |
|
from feasibility_agent import feasibility_agent_func |
|
|
|
|
|
|
|
|
|
def create_excel(df): |
|
|
|
wb = Workbook() |
|
ws = wb.active |
|
ws.title = "Use Cases" |
|
|
|
|
|
headers = ['Use Case', 'Description', 'URLs'] |
|
ws.append(headers) |
|
|
|
|
|
for _, row in df.iterrows(): |
|
try: |
|
use_case = row['use_case'] |
|
description = row['description'] |
|
urls = row['urls_list'] |
|
|
|
ws.append([use_case, description, None]) |
|
if urls: |
|
for url_index, url in enumerate(urls): |
|
cell = ws.cell(row=ws.max_row, column=3) |
|
cell.value = url |
|
cell.hyperlink = url |
|
cell.font = Font(color="0000FF", underline="single") |
|
|
|
|
|
if url_index < len(urls) - 1: |
|
ws.append([None, None, None]) |
|
except KeyError as e: |
|
print(f"Missing key in DataFrame row: {e}") |
|
except Exception as e: |
|
print(f"Unexpected error while processing row: {e}") |
|
|
|
excel_file_path = "GenAI_use_cases_feasibility.xlsx" |
|
wb.save(excel_file_path) |
|
return excel_file_path |
|
|
|
|
|
|
|
def pd_creation(report): |
|
|
|
pd_dict = feasibility_agent_func(report) |
|
|
|
|
|
df = pd.DataFrame(pd_dict) |
|
|
|
|
|
data = df.values.tolist() |
|
|
|
|
|
excel_file_path = create_excel(df) |
|
|
|
return data, excel_file_path |
|
|
|
|
|
|
|
def main(user_input): |
|
|
|
agentstate_result = research_agent(user_input) |
|
|
|
|
|
urls, content = extract_urls(agentstate_result) |
|
pdf_urls, html_urls = urls_classify_list(urls) |
|
html_docs = clean_and_extract_html_data(html_urls) |
|
|
|
|
|
vectorstore_writing(html_docs) |
|
|
|
|
|
company_name = agentstate_result['company'] |
|
industry_name = agentstate_result['industry'] |
|
|
|
if company_name: |
|
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.' |
|
else: |
|
topic = f'GenAI Usecases in {industry_name}. Explore {industry_name} GenAI applications, trends, challenges, and opportunities.' |
|
max_analysts = 3 |
|
|
|
report = usecase_agent_func(topic, max_analysts) |
|
pd_dict, excel_file_path = pd_creation(report) |
|
|
|
|
|
report_file_path = "generated_report.md" |
|
with open(report_file_path, "w") as f: |
|
f.write(report) |
|
|
|
return report, report_file_path , excel_file_path |
|
|
|
|
|
|
|
examples = [ |
|
"AI in healthcare industry", |
|
"How is the retail industry leveraging AI and ML?", |
|
"AI applications in automotive manufacturing" |
|
] |
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
|
|
gr.HTML("<center><h1>UseCaseGenie - Discover GenAI Use cases for your company and Industry! π€π§βπ³.</h1><center>") |
|
gr.Markdown("""#### This GenAI Assistant π€ helps you discover and explore Generative AI use cases for your company and industry. |
|
You can download the generated use case report as a <b>Markdown file</b> and a <b>Feasibility Excel file</b> to gain insights and explore relevant GenAI applications. |
|
### <b>Steps:</b> |
|
1. <b>Enter your query</b> regarding any company or industry. |
|
2. <b>Click on the 'Submit' button</b> and wait for the GenAI assistant to generate the report. |
|
3. <b>Download the generated report and Excel file.<b> |
|
4. Explore the GenAI use cases and URLs for further analysis. |
|
""") |
|
|
|
|
|
|
|
with gr.Row(): |
|
user_input = gr.Textbox(label="Enter your Query", placeholder='Type_here...') |
|
|
|
|
|
with gr.Row(): |
|
submit_button = gr.Button("Submit") |
|
clear_btn = gr.ClearButton([user_input], value='Clear') |
|
|
|
|
|
with gr.Row(): |
|
gr.Examples(examples=examples, inputs=user_input) |
|
|
|
|
|
with gr.Row(): |
|
|
|
download_report_button = gr.File(label="Usecases Report") |
|
|
|
|
|
download_excel_button = gr.File(label="Feasibility Excel File") |
|
|
|
|
|
with gr.Row(): |
|
report_output = gr.Markdown() |
|
|
|
submit_button.click(main, inputs=[user_input], outputs=[report_output, download_report_button,download_excel_button]) |
|
|
|
|
|
demo.launch() |
|
|