Ki-Seki commited on
Commit
fa48de8
·
1 Parent(s): bfc6418

chore: refactor app.py for improved readability and performance

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -2,6 +2,12 @@ import gradio as gr
2
 
3
  from autotab import AutoTab
4
  import json
 
 
 
 
 
 
5
 
6
 
7
  def auto_tabulator_completion(
@@ -11,7 +17,9 @@ def auto_tabulator_completion(
11
  model_name,
12
  generation_config,
13
  save_every,
14
- ):
 
 
15
  output_file_name = "ouput.xlsx"
16
  autotab = AutoTab(
17
  in_file_path=in_file.name,
@@ -19,13 +27,16 @@ def auto_tabulator_completion(
19
  out_file_path=output_file_name,
20
  max_examples=max_examples,
21
  model_name=model_name,
22
- api_key="sk-exhahhjfqyanmwewndukcqtrpegfdbwszkjucvcpajdufiah",
23
- base_url="https://public-beta-api.siliconflow.cn/v1",
24
  generation_config=json.loads(generation_config),
25
  save_every=save_every,
26
  )
 
27
  autotab.run()
28
- return output_file_name, autotab.data[:15]
 
 
29
 
30
 
31
  # Gradio interface
@@ -35,17 +46,23 @@ inputs = [
35
  value="You are a helpful assistant. Help me finish the task.",
36
  label="Instruction",
37
  ),
38
- gr.Slider(value=5, minimum=1, maximum=100, label="Max Examples"),
39
  gr.Textbox(value="Qwen/Qwen2-7B-Instruct", label="Model Name"),
40
  gr.Textbox(
41
  value='{"temperature": 0, "max_tokens": 128}',
42
  label="Generation Config in Dict",
43
  ),
44
- gr.Slider(value=10, minimum=1, maximum=1000, label="Save Every N Steps"),
 
 
 
 
45
  ]
46
 
47
  outputs = [
 
48
  gr.File(label="Output Excel File"),
 
49
  gr.Dataframe(label="First 15 rows."),
50
  ]
51
 
 
2
 
3
  from autotab import AutoTab
4
  import json
5
+ import time
6
+ import pandas as pd
7
+
8
+
9
+ def convert_seconds_to_time(seconds):
10
+ return time.strftime("%H:%M:%S", time.gmtime(seconds))
11
 
12
 
13
  def auto_tabulator_completion(
 
17
  model_name,
18
  generation_config,
19
  save_every,
20
+ api_key,
21
+ base_url,
22
+ ) -> tuple[str, str, str, pd.DataFrame]:
23
  output_file_name = "ouput.xlsx"
24
  autotab = AutoTab(
25
  in_file_path=in_file.name,
 
27
  out_file_path=output_file_name,
28
  max_examples=max_examples,
29
  model_name=model_name,
30
+ api_key=api_key,
31
+ base_url=base_url,
32
  generation_config=json.loads(generation_config),
33
  save_every=save_every,
34
  )
35
+ start = time.time()
36
  autotab.run()
37
+ time_taken = time.strftime("%H:%M:%S", time.gmtime(time.time() - start))
38
+
39
+ return time_taken, output_file_name, autotab.query_example, autotab.data[:15]
40
 
41
 
42
  # Gradio interface
 
46
  value="You are a helpful assistant. Help me finish the task.",
47
  label="Instruction",
48
  ),
49
+ gr.Slider(value=5, minimum=1, maximum=50, step=1, label="Max Examples"),
50
  gr.Textbox(value="Qwen/Qwen2-7B-Instruct", label="Model Name"),
51
  gr.Textbox(
52
  value='{"temperature": 0, "max_tokens": 128}',
53
  label="Generation Config in Dict",
54
  ),
55
+ gr.Slider(value=100, minimum=1, maximum=1000, step=1, label="Save Every N Steps"),
56
+ gr.Textbox(
57
+ value="sk-exhahhjfqyanmwewndukcqtrpegfdbwszkjucvcpajdufiah", label="API Key"
58
+ ),
59
+ gr.Textbox(value="https://public-beta-api.siliconflow.cn/v1", label="Base URL"),
60
  ]
61
 
62
  outputs = [
63
+ gr.Textbox(label="Time Taken"),
64
  gr.File(label="Output Excel File"),
65
+ gr.Textbox(label="Query Example"),
66
  gr.Dataframe(label="First 15 rows."),
67
  ]
68