ewgewgewg commited on
Commit
32ba37a
1 Parent(s): 3717d6e

add feature for custom fields

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -5,7 +5,8 @@ import yake
5
 
6
  demo = gr.Blocks()
7
 
8
- def generate(input, attempted_items, offset):
 
9
  # Step 1: Import
10
 
11
  pdfFileObj = open(input.name, 'rb')
@@ -34,6 +35,11 @@ def generate(input, attempted_items, offset):
34
  for kw in keywords:
35
  kw_list.append(kw[0])
36
 
 
 
 
 
 
37
  # Step 3: Process for Assignment
38
  output = {}
39
  for kw in kw_list:
@@ -110,10 +116,16 @@ def offset_changer(offset_input):
110
  offset: int(offset_input)
111
  }
112
 
 
 
 
 
 
113
  with demo:
114
 
115
  attempted_items = gr.State(50)
116
  offset = gr.State(0)
 
117
 
118
  gr.Markdown("# PDF to Index")
119
 
@@ -133,7 +145,14 @@ with demo:
133
  attempted_items_input.change(attempted_items_changer, [attempted_items_input], [attempted_items])
134
  offset_input.change(offset_changer, [offset_input], [offset])
135
 
136
- gr.HTML("<p><em>Attempted Items is the number of terms intended for index (output may be slightly lower), while Page Offset is a value added to each page number found in the file. In the case of invalid values, Attempted Items will default to 50 and Page Offset will default to 0.</em></p>")
 
 
 
 
 
 
 
137
 
138
  gr.Markdown("---")
139
 
@@ -148,7 +167,7 @@ with demo:
148
 
149
  convert_button.click(
150
  fn=generate,
151
- inputs=[uploaded_file, attempted_items, offset],
152
  outputs=[index],
153
  )
154
 
 
5
 
6
  demo = gr.Blocks()
7
 
8
+ def generate(input, attempted_items, offset, custom):
9
+
10
  # Step 1: Import
11
 
12
  pdfFileObj = open(input.name, 'rb')
 
35
  for kw in keywords:
36
  kw_list.append(kw[0])
37
 
38
+ if(len(custom)):
39
+ split_custom = custom.split(';')
40
+ for kw in split_custom:
41
+ kw_list.append(kw)
42
+
43
  # Step 3: Process for Assignment
44
  output = {}
45
  for kw in kw_list:
 
116
  offset: int(offset_input)
117
  }
118
 
119
+ def custom_changer (custom_input):
120
+ return {
121
+ custom: custom_input
122
+ }
123
+
124
  with demo:
125
 
126
  attempted_items = gr.State(50)
127
  offset = gr.State(0)
128
+ custom = gr.State("")
129
 
130
  gr.Markdown("# PDF to Index")
131
 
 
145
  attempted_items_input.change(attempted_items_changer, [attempted_items_input], [attempted_items])
146
  offset_input.change(offset_changer, [offset_input], [offset])
147
 
148
+ gr.HTML("<p><em>Attempted Items is the number of terms intended for index (output may be slightly lower), while Page Offset is a value added to each page number found in the file. In the case of invalid values, Attempted Items will default to 50 and Page Offset will default to 0. If the fields do not produce expected values, you may be clicking too quickly -- please try again.</em></p>")
149
+
150
+ with gr.Row():
151
+ custom_input = gr.Textbox(value="", show_label=True, label="Custom")
152
+ custom_input.change(custom_changer, [custom_input], [custom])
153
+
154
+ gr.HTML("<p><em>You can add semicolon-separated values in Custom to add custom fields to index. If the fields do not produce expected values, you may be clicking too quickly -- please try again.</em></p>")
155
+
156
 
157
  gr.Markdown("---")
158
 
 
167
 
168
  convert_button.click(
169
  fn=generate,
170
+ inputs=[uploaded_file, attempted_items, offset, custom],
171
  outputs=[index],
172
  )
173