Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,6 +38,20 @@ print("Loading the transformer model...")
|
|
38 |
# Initialize the transformer vectorizer
|
39 |
transformer_vectorizer = TransformerVectorizer()
|
40 |
vectorizer = TfidfVectorizer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def toggle_visibility(input_type):
|
42 |
user_input_visible = input_type == "Text Input"
|
43 |
file_upload_visible = input_type == "File Upload"
|
@@ -287,10 +301,16 @@ with demo:
|
|
287 |
"Enter a contract or clause you want to analysis)."
|
288 |
)
|
289 |
input_type = gr.Radio(choices=["Text Input", "File Upload"], label="Select Input Method")
|
290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
-
file_upload = gr.File(label="Upload File", file_types=[".txt"], visible=False) # Initially hidden
|
293 |
-
input_type.change(toggle_visibility, inputs=input_type, outputs=[text, file_upload])
|
294 |
gr.Markdown(
|
295 |
"""
|
296 |
<hr/>
|
|
|
38 |
# Initialize the transformer vectorizer
|
39 |
transformer_vectorizer = TransformerVectorizer()
|
40 |
vectorizer = TfidfVectorizer()
|
41 |
+
def process_input(input_type, user_input, uploaded_file):
|
42 |
+
print('ooooocr')
|
43 |
+
if input_type == "File Upload" and uploaded_file is not None:
|
44 |
+
|
45 |
+
with open(uploaded_file.name, "rb") as f:
|
46 |
+
image = f.read()
|
47 |
+
results = reader.readtext(image)
|
48 |
+
|
49 |
+
extracted_text = ' '.join([text[1] for text in results])
|
50 |
+
print("text:")
|
51 |
+
print(extracted_text)
|
52 |
+
return extracted_text
|
53 |
+
elif input_type == "Text Input":
|
54 |
+
return user_input
|
55 |
def toggle_visibility(input_type):
|
56 |
user_input_visible = input_type == "Text Input"
|
57 |
file_upload_visible = input_type == "File Upload"
|
|
|
301 |
"Enter a contract or clause you want to analysis)."
|
302 |
)
|
303 |
input_type = gr.Radio(choices=["Text Input", "File Upload"], label="Select Input Method")
|
304 |
+
user_input = gr.Textbox(label="Enter some words:",visible=False,value="The Employee is entitled to two weeks of paid vacation annually, to be scheduled at the mutual convenience of the Employee and Employer.")
|
305 |
+
|
306 |
+
file_upload = gr.File(label="Upload File", file_types=[".jpg", ".png",".txt"], visible=False) # Initially hidden
|
307 |
+
input_type.change(toggle_visibility, inputs=input_type, outputs=[user_input, file_upload])
|
308 |
+
|
309 |
+
submit_button = gr.Button("Submit")
|
310 |
+
text = gr.Textbox(label="Extracted Text")
|
311 |
+
|
312 |
+
submit_button.click(process_input, inputs=[input_type, user_input, file_upload], outputs=output_text)
|
313 |
|
|
|
|
|
314 |
gr.Markdown(
|
315 |
"""
|
316 |
<hr/>
|