import gradio as gr from pandasai_tool import pandas_ai_res import time # import csv or xlsx file and use input as df # pandas_ai_res function will return resultr with gr.Blocks() as demo: gr.Label("πŸ—£λ§λ‘œ ν•˜λŠ” 데이터 뢄석") gr.Markdown("(μ•ˆλ‚΄) 데이터 νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ³ , 뢄석을 λΆ€νƒν•˜μ„Έμš”") # uploaded_file = gr.File(label="파일 μ—…λ‘œλ“œ") # chatbot = gr.Chatbot() # msg = gr.Textbox() # clear = gr.ClearButton([msg, chatbot], label="μ±„νŒ… 기둝 μ‚­μ œ") # # def respond(file, message, chat_history): # bot_message = pandas_ai_res(file, message) # chat_history.append((message, bot_message)) # # time.sleep(2) # return "", chat_history # # msg.submit(respond, [uploaded_file, msg, chatbot], [msg, chatbot]) gr.Interface( fn=pandas_ai_res, inputs=["file", "text"], outputs="text" ) if __name__ == "__main__": demo.launch(share=True) # # import gradio as gr # import pandas as pd # from huggingface_hub.hf_api import create_repo, upload_file, HfApi # from huggingface_hub.repository import Repository # import subprocess # import os # import tempfile # # # import sweetviz as sv # # # def analyze_datasets(dataset, dataset_name, token, column=None, pairwise="off"): # df = pd.read_csv(dataset.name) # username = HfApi().whoami(token=token)["name"] # if column is not None: # analyze_report = sv.analyze(df, target_feat=column, pairwise_analysis=pairwise) # else: # analyze_report = sv.analyze(df, pairwise_analysis=pairwise) # analyze_report.show_html('./index.html', open_browser=False) # repo_url = create_repo(f"{username}/{dataset_name}", repo_type="space", token=token, space_sdk="static", # private=False) # # upload_file(path_or_fileobj="./index.html", path_in_repo="index.html", repo_id=f"{username}/{dataset_name}", # repo_type="space", token=token) # readme = f"---\ntitle: {dataset_name}\nemoji: ✨\ncolorFrom: green\ncolorTo: red\nsdk: static\npinned: false\ntags:\n- dataset-report\n---" # with open("README.md", "w+") as f: # f.write(readme) # upload_file(path_or_fileobj="./README.md", path_in_repo="README.md", repo_id=f"{username}/{dataset_name}", # repo_type="space", token=token) # # return f"Your dataset report will be ready at {repo_url}" # # # # # # # with gr.Blocks() as demo: # main_title = gr.Markdown("""# Easy AnalysisπŸͺ„πŸŒŸβœ¨""") # main_desc = gr.Markdown( # """This app enables you to run three type of dataset analysis and pushes the interactive reports to your Hugging Face Hub profile as a Space. It uses SweetViz in the back.""") # with gr.Tabs(): # with gr.TabItem("Analyze") as analyze: # with gr.Row(): # with gr.Column(): # title = gr.Markdown(""" ## Analyze Dataset """) # description = gr.Markdown( # "Analyze a dataset or predictive variables against a target variable in a dataset (enter a column name to column section if you want to compare against target value). You can also do pairwise analysis, but it has quadratic complexity.") # dataset = gr.File(label="Dataset") # column = gr.Text(label="Compare dataset against a target variable (Optional)") # pairwise = gr.Radio(["off", "on"], label="Enable pairwise analysis") # token = gr.Textbox(label="Your Hugging Face Token") # dataset_name = gr.Textbox(label="Dataset Name") # pushing_desc = gr.Markdown( # "This app needs your Hugging Face Hub token and a unique name for your dataset report.") # inference_run = gr.Button("Infer") # inference_progress = gr.StatusTracker(cover_container=True) # outcome = gr.outputs.Textbox() # inference_run.click( # analyze_datasets, # inputs=[dataset, dataset_name, token, column, pairwise], # outputs=outcome, # status_tracker=inference_progress, # ) # with gr.TabItem("Compare Splits") as compare_splits: # with gr.Row(): # with gr.Column(): # title = gr.Markdown(""" ## Compare Splits""") # description = gr.Markdown( # "Split a dataset and compare splits. You need to give a fraction, e.g. 0.8.") # dataset = gr.File(label="Dataset") # split_ratio = gr.Number(label="Split Ratios") # pushing_desc = gr.Markdown( # "This app needs your Hugging Face Hub token and a unique name for your dataset report.") # token = gr.Textbox(label="Your Hugging Face Token") # dataset_name = gr.Textbox(label="Dataset Name") # inference_run = gr.Button("Infer") # inference_progress = gr.StatusTracker(cover_container=True) # # outcome = gr.outputs.Textbox() # inference_run.click( # compare_dataset_splits, # inputs=[dataset, dataset_name, token, split_ratio], # outputs=outcome, # status_tracker=inference_progress, # ) # # with gr.TabItem("Compare Subsets") as compare_subsets: # with gr.Row(): # with gr.Column(): # title = gr.Markdown(""" ## Compare Subsets""") # description = gr.Markdown( # "Compare subsets of a dataset, e.g. you can pick Age Group column and compare adult category against young.") # dataset = gr.File(label="Dataset") # column = gr.Text(label="Enter column:") # category = gr.Text(label="Enter category:") # pushing_desc = gr.Markdown( # "This app needs your Hugging Face Hub token and a unique name for your dataset report.") # token = gr.Textbox(label="Your Hugging Face Token") # dataset_name = gr.Textbox(label="Dataset Name") # inference_run = gr.Button("Run Analysis") # inference_progress = gr.StatusTracker(cover_container=True) # # outcome = gr.outputs.Textbox() # inference_run.click( # compare_column_values, # inputs=[dataset, dataset_name, token, column, category], # outputs=outcome, # status_tracker=inference_progress, # )