cohit's picture
Upload folder using huggingface_hub
0827183 verified
raw
history blame
1.75 kB
import gradio as gr
from conn import connector
import time
import csv
import pandas as pd
import os,re,zipfile
conn=connector()
info=conn.generate()
info=conn.start_conversation(info['token'])
def resp(message, intensity):
"""Direct Line Api v.3 connection to CoPilot"""
retval = conn.send_message(info['token'],info['conversationId'],'cohitai',message)
time.sleep(4)
return conn.get_message(info['token'],info['conversationId'])["activities"][-1]["text"]
def upload_file(files):
return [pd.read_excel(file.name) for file in files]
def process_excel_files(files):
temp_list=[(file,fetch_sheet_names(file)) for file in files]
df = [pd.read_excel(tup[0],sheet) for tup in temp_list for sheet in tup[1]]
return df
def fetch_sheet_names(path):
sheets=[]
with zipfile.ZipFile(path,'r') as zip_ref:
xml=zip_ref.read("xl/workbook.xml").decode("utf-8")
for s_tag in re.findall("<sheet [^>]*",xml) : sheets.append(re.search('name="[^"]*',s_tag).group(0)[6:])
return sheets
with gr.Blocks() as demo:
gr.Markdown("# Say Hello to Validify-Bot, Built on Microsoft Co-Pilot Backend, with Direct Line API V. 3.0")
inp = gr.Textbox(placeholder="Please Enter the text here.")
out = gr.Textbox()
inp.change(resp, inp, out)
file_output = gr.Files()
upload_button = gr.UploadButton("Click to Upload Excel Files", file_types=["file"], file_count="multiple")
dataset = gr.Dataframe(row_count=5)
upload_button.upload(fn=process_excel_files, inputs=upload_button, outputs=dataset)
if __name__ == "__main__":
demo.launch(share=True)
# demo = gr.Interface(
# fn=resp,
# # fn=file_input,
# inputs=["text","slider"],
# outputs=["text"],
# )