joaomorossini commited on
Commit
d21c9dd
1 Parent(s): 23fee25

Implement download log functionality

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -21,6 +21,21 @@ logs_columns = ['Abstract', 'Model', 'Results']
21
  logs_df = PandasDataFrame(columns=logs_columns)
22
 
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def build_context(row):
25
  subsector_name = row['Subsector']
26
  context = f"Subsector name: {subsector_name}. "
@@ -67,7 +82,7 @@ def on_select(evt: gr.SelectData): # SelectData is a subclass of EventData
67
  return name_accordion, definition, keywords, does_include, does_not_include
68
 
69
 
70
- # with gr.Blocks(theme=theme) as startup_genome_demo:
71
  with gr.Blocks(css=css, js=js) as demo:
72
  state_lotto = gr.State()
73
  selected_x_labels = gr.State()
@@ -114,6 +129,7 @@ with gr.Blocks(css=css, js=js) as demo:
114
  label_result = gr.Label(num_top_classes=None)
115
  with gr.Column(scale=6):
116
  reasoning = gr.Markdown(label="Reasoning", elem_classes=['reasoning_results'])
 
117
  with gr.Tab("Subsector definitions"):
118
  with gr.Row():
119
  with gr.Column(scale=4):
@@ -125,20 +141,30 @@ with gr.Blocks(css=css, js=js) as demo:
125
  value="Mixed Reality, 360 video, frame rate, metaverse, virtual world, cross reality, Artificial intelligence, computer vision")
126
  does_include = gr.Textbox(label="Does include", lines=4)
127
  does_not_include = gr.Textbox(label="Does not include", lines=3)
 
128
  with gr.Tab("Logs"):
129
  output_dataframe = gr.Dataframe(
130
  value=logs_df,
131
  type="pandas",
132
  height=500,
133
- headers=logs_columns,
134
  interactive=False,
135
  column_widths=["45%", "10%", "45%"],
136
  )
 
 
 
 
137
 
138
  btn_get_result.click(
139
  fn=click_button,
140
  inputs=[dropdown_model, api_key, abstract_description],
141
  outputs=[label_result, reasoning, output_dataframe])
 
 
 
 
 
142
  df_subsectors.select(
143
  fn=on_select,
144
  outputs=[subsector_name, s1_definition, s1_keywords, does_include, does_not_include]
 
21
  logs_df = PandasDataFrame(columns=logs_columns)
22
 
23
 
24
+ def download_logs():
25
+ global logs_df
26
+ # Check for the current operating system's desktop path
27
+ if os.name == 'nt': # For Windows
28
+ desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
29
+ else: # For macOS and Linux
30
+ desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
31
+
32
+ # Define the path to save the CSV file on the desktop
33
+ file_path = os.path.join(desktop, 'classification_logs.csv')
34
+
35
+ # Save the DataFrame to the CSV file on the desktop
36
+ logs_df.to_csv(file_path)
37
+
38
+
39
  def build_context(row):
40
  subsector_name = row['Subsector']
41
  context = f"Subsector name: {subsector_name}. "
 
82
  return name_accordion, definition, keywords, does_include, does_not_include
83
 
84
 
85
+ # --- GRADIO INTERFACE --- #
86
  with gr.Blocks(css=css, js=js) as demo:
87
  state_lotto = gr.State()
88
  selected_x_labels = gr.State()
 
129
  label_result = gr.Label(num_top_classes=None)
130
  with gr.Column(scale=6):
131
  reasoning = gr.Markdown(label="Reasoning", elem_classes=['reasoning_results'])
132
+
133
  with gr.Tab("Subsector definitions"):
134
  with gr.Row():
135
  with gr.Column(scale=4):
 
141
  value="Mixed Reality, 360 video, frame rate, metaverse, virtual world, cross reality, Artificial intelligence, computer vision")
142
  does_include = gr.Textbox(label="Does include", lines=4)
143
  does_not_include = gr.Textbox(label="Does not include", lines=3)
144
+
145
  with gr.Tab("Logs"):
146
  output_dataframe = gr.Dataframe(
147
  value=logs_df,
148
  type="pandas",
149
  height=500,
150
+ headers=['Abstract', 'Model', 'Results'],
151
  interactive=False,
152
  column_widths=["45%", "10%", "45%"],
153
  )
154
+ btn_export = gr.Button(
155
+ value="Export to CSV",
156
+ size="sm",
157
+ )
158
 
159
  btn_get_result.click(
160
  fn=click_button,
161
  inputs=[dropdown_model, api_key, abstract_description],
162
  outputs=[label_result, reasoning, output_dataframe])
163
+
164
+ btn_export.click(
165
+ fn=download_logs,
166
+ )
167
+
168
  df_subsectors.select(
169
  fn=on_select,
170
  outputs=[subsector_name, s1_definition, s1_keywords, does_include, does_not_include]