Preeda commited on
Commit
68a9be6
·
1 Parent(s): f7a8e89
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -12,32 +12,48 @@ wb = None
12
  def greet(name):
13
  return "Hello " + name + "!!"
14
 
15
- # Load the Excel file from Github
16
- def load_excel_from_github():
17
  global df, wb
18
- url = "https://github.com/mmlanla/image_share/blob/main/mass_update_sales_info_lastest.xlsx?raw=true"
19
- response = requests.get(url)
20
- file_data = BytesIO(response.content)
21
- wb = load_workbook(file_data)
22
  sheet = wb.active
23
  df = pd.DataFrame(sheet.values)
24
  df.columns = df.iloc[0] # Set the first row as column names
25
  df = df[1:] # Remove the first row from the DataFrame
26
  options = df['et_title_variation_name'].unique().tolist()
27
- print('options', options)
28
  return options
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # Create the Gradio interface
31
  with gr.Blocks() as demo:
32
  with gr.Row():
33
  with gr.Column():
34
- button_load_excel_from_github = gr.Button("Load Excel from GitHub")
35
- output_message = gr.Textbox(label="Output Message", interactive=False)
36
- button_load_excel_from_github.click(
37
- fn=load_excel_from_github,
38
- inputs=[],
39
- outputs=output_message
40
- )
 
 
 
 
 
41
 
42
  if 0:
43
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
12
  def greet(name):
13
  return "Hello " + name + "!!"
14
 
15
+ # Load the Excel file
16
+ def load_excel(file):
17
  global df, wb
18
+ wb = load_workbook(file.name)
 
 
 
19
  sheet = wb.active
20
  df = pd.DataFrame(sheet.values)
21
  df.columns = df.iloc[0] # Set the first row as column names
22
  df = df[1:] # Remove the first row from the DataFrame
23
  options = df['et_title_variation_name'].unique().tolist()
24
+ print('options',options)
25
  return options
26
 
27
+ # Search and display table
28
+ def search_variations(query):
29
+ global df
30
+ print('query',query)
31
+ # print('df',df)
32
+ if df is not None:
33
+ filtered_df = df[df['et_title_variation_name'].str.contains(query, na=False)]
34
+ print('filtered_df',filtered_df['et_title_product_name'],filtered_df['et_title_variation_name'])
35
+ # return []
36
+ return filtered_df
37
+ # return filtered_df.to_dict(orient='records')
38
+ return []
39
+
40
+
41
  # Create the Gradio interface
42
  with gr.Blocks() as demo:
43
  with gr.Row():
44
  with gr.Column():
45
+
46
+ upload = gr.File(label="Upload Excel File", file_types=[".xlsx"])
47
+ upload.upload(load_excel, [upload])
48
+ search_input = gr.Textbox(label="Search Text")
49
+
50
+
51
+ table = gr.Dataframe(headers=["et_title_product_id","et_title_product_name", "et_title_variation_id" "et_title_variation_name", "et_title_parent_sku", "et_title_variation_sku", "et_title_variation_price","et_title_variation_stock"], datatype=["str", "str", "str", "str", "str", "str", "str", "str"], interactive=True)
52
+
53
+ search_input.change(search_variations, [search_input], table)
54
+
55
+ save_button = gr.Button("Save Edited Table")
56
+ output_file = gr.File(label="Downloaded Edited Excel File")
57
 
58
  if 0:
59
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")