Ki-Seki commited on
Commit
d6c98c4
·
1 Parent(s): 938006b

feat: gradio support

Browse files
Files changed (3) hide show
  1. app.py +58 -0
  2. autotab.py +1 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from autotab import AutoTab
4
+ import json
5
+
6
+
7
+ def auto_tabulator_completion(
8
+ in_file,
9
+ instruction,
10
+ max_examples,
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,
18
+ instruction=instruction,
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
32
+ inputs = [
33
+ gr.File(label="Input Excel File"),
34
+ gr.Textbox(
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
+
52
+ gr.Interface(
53
+ fn=auto_tabulator_completion,
54
+ inputs=inputs,
55
+ outputs=outputs,
56
+ title="Auto Tabulator Completion",
57
+ description="Automatically complete missing output values in tabular data based on in-context learning.",
58
+ ).launch()
autotab.py CHANGED
@@ -114,5 +114,6 @@ class AutoTab:
114
  data.at[i, field_name] = extracted_fields.get(field_name, "")
115
  if i % self.save_every == 0:
116
  data.to_excel(self.out_file_path, index=False)
 
117
  data.to_excel(self.out_file_path, index=False)
118
  print(f"Results saved to {self.out_file_path}")
 
114
  data.at[i, field_name] = extracted_fields.get(field_name, "")
115
  if i % self.save_every == 0:
116
  data.to_excel(self.out_file_path, index=False)
117
+ self.data = data
118
  data.to_excel(self.out_file_path, index=False)
119
  print(f"Results saved to {self.out_file_path}")
requirements.txt CHANGED
@@ -2,3 +2,4 @@ pandas
2
  openai
3
  argparse
4
  openpyxl
 
 
2
  openai
3
  argparse
4
  openpyxl
5
+ gradio