MarioPrzBasto commited on
Commit
c072a2e
·
1 Parent(s): b4f6378

Add application file

Browse files
Files changed (1) hide show
  1. app.py +1 -136
app.py CHANGED
@@ -271,142 +271,7 @@ def generate_results_dataframe(results):
271
  dfs["statistics"] = pd.DataFrame(data, columns=["Metric", "Value"])
272
 
273
  return dfs
274
-
275
- with gr.Blocks(title="Text Similarity Detector") as demo:
276
- gr.Markdown("# 🔍 Text Similarity Detector with Image Extraction")
277
- gr.Markdown("""
278
- This tool analyzes the similarity between texts extracted from an image and reference key texts.
279
- It can identify:
280
- - Direct similar texts
281
- - Key text fragments within the texts
282
- - Text combinations that match key texts
283
- """)
284
-
285
- with gr.Tabs() as tabs:
286
- with gr.TabItem("Image Analysis"):
287
- with gr.Row():
288
- with gr.Column(scale=1): # Column for inputs on the left
289
- input_image = gr.Image(label="Upload an image to extract text", type="pil", height=600)
290
- key_texts_image = gr.Textbox(
291
- label="Key Texts for Comparison",
292
- placeholder="Paste your key texts here (one per line)",
293
- lines=5
294
- )
295
- # with gr.Row():
296
- # key_texts_image = gr.Textbox(
297
- # label="Key Texts for Comparison",
298
- # placeholder="Paste your key texts here (one per line)",
299
- # lines=5
300
- # )
301
-
302
- # min_similarity_per_key_image = gr.Textbox(
303
- # label="Minimum Similarity for Each Key Text (%)",
304
- # placeholder="Enter one value per line, matching the key texts",
305
- # lines=5
306
- # )
307
-
308
- with gr.Row():
309
- similarity_threshold_image = gr.Slider(
310
- label="Similarity Threshold (%)",
311
- minimum=50,
312
- maximum=100,
313
- value=70,
314
- step=1
315
- )
316
- fragment_threshold_image = gr.Slider(
317
- label="Fragment Similarity Threshold (%)",
318
- minimum=50,
319
- maximum=100,
320
- value=70,
321
- step=1
322
- )
323
-
324
- analyze_image_btn = gr.Button("Analyze Image", variant="primary")
325
-
326
- with gr.Column(scale=1): # Column for outputs on the right
327
- gpu_available = gr.Checkbox(label="Used GPU")
328
- extracted_texts = gr.Textbox(label="Extracted Texts from the Image", lines=5)
329
- html_output = gr.HTML(label="Similarity Report")
330
- with gr.Tabs():
331
- with gr.TabItem("Statistics"):
332
- statistics_output = gr.Dataframe(label="Statistics")
333
- with gr.TabItem("Direct Similarity"):
334
- similar_texts_output = gr.Dataframe(label="Direct Similar Texts")
335
- with gr.TabItem("Fragments"):
336
- fragments_output = gr.Dataframe(label="Texts with Fragments")
337
- with gr.TabItem("Combined"):
338
- combined_output = gr.Dataframe(label="Combined Texts")
339
-
340
- with gr.TabItem("Manual Analysis"):
341
- with gr.Row():
342
- with gr.Column(scale=1): # Column for inputs on the left
343
- input_texts = gr.Textbox(
344
- label="List of Texts for Analysis",
345
- placeholder="Paste your list of texts here (one per line)",
346
- lines=10
347
- )
348
- key_texts_input = gr.Textbox(
349
- label="Key Texts for Comparison",
350
- placeholder="Paste your key texts here (one per line)",
351
- lines=5
352
- )
353
- # with gr.Row():
354
- # key_texts_input = gr.Textbox(
355
- # label="Key Texts for Comparison",
356
- # placeholder="Paste your key texts here (one per line)",
357
- # lines=5
358
- # )
359
-
360
- # min_similarity_per_key_input = gr.Textbox(
361
- # label="Minimum Similarity for Each Key Text (%)",
362
- # placeholder="Enter one value per line, matching the key texts",
363
- # lines=5
364
- # )
365
-
366
- with gr.Row():
367
- similarity_threshold = gr.Slider(
368
- label="Similarity Threshold (%)",
369
- minimum=50,
370
- maximum=100,
371
- value=70,
372
- step=1
373
- )
374
- fragment_threshold = gr.Slider(
375
- label="Fragment Similarity Threshold (%)",
376
- minimum=50,
377
- maximum=100,
378
- value=70,
379
- step=1
380
- )
381
-
382
- analyze_btn = gr.Button("Analyze Image", variant="primary")
383
-
384
- with gr.Column(scale=1): # Column for outputs on the right
385
- html_output_manual = gr.HTML(label="Manual Similarity Report")
386
- with gr.Tabs():
387
- with gr.TabItem("Statistics"):
388
- statistics_output_manual = gr.Dataframe(label="Statistics")
389
- with gr.TabItem("Direct Similarity"):
390
- similar_texts_output_manual = gr.Dataframe(label="Direct Similar Texts")
391
- with gr.TabItem("Fragments"):
392
- fragments_output_manual = gr.Dataframe(label="Texts with Fragments")
393
- with gr.TabItem("Combined"):
394
- combined_output_manual = gr.Dataframe(label="Combined Texts")
395
-
396
- # Connect the image processing function to the button
397
- analyze_image_btn.click(
398
- process_image,
399
- inputs=[input_image, key_texts_image, similarity_threshold_image, fragment_threshold_image],
400
- outputs=[html_output, statistics_output, similar_texts_output, fragments_output, combined_output, extracted_texts, gpu_available]
401
- )
402
-
403
- # Connect the manual text processing function to the button
404
- analyze_btn.click(
405
- process_manual_input,
406
- inputs=[input_texts, key_texts_input, similarity_threshold, fragment_threshold],
407
- outputs=[html_output_manual, statistics_output_manual, similar_texts_output_manual, fragments_output_manual, combined_output_manual]
408
- )
409
-
410
  #app = gr.mount_gradio_app(app, demo, path="/")
411
 
412
  @app.get("/api")
 
271
  dfs["statistics"] = pd.DataFrame(data, columns=["Metric", "Value"])
272
 
273
  return dfs
274
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  #app = gr.mount_gradio_app(app, demo, path="/")
276
 
277
  @app.get("/api")