Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def search_pattern(fulltext, pattern, method):
|
| 5 |
+
fulltext = fulltext.replace('\n','')
|
| 6 |
+
pattern = pattern.replace('\n','')
|
| 7 |
+
if method == 'Naive-Exact-Match':
|
| 8 |
+
import time
|
| 9 |
+
start = time.time()
|
| 10 |
+
occurrence = 0
|
| 11 |
+
for i in range(0,len(fulltext)-len(pattern)+1):
|
| 12 |
+
found = 1
|
| 13 |
+
for l in range(len(pattern)):
|
| 14 |
+
if fulltext[i+l] != pattern[l]:
|
| 15 |
+
found = 0
|
| 16 |
+
if found:
|
| 17 |
+
occurrence += 1
|
| 18 |
+
print("Found ", fulltext[i:i+len(pattern)], ' locating at position ', i+1)
|
| 19 |
+
|
| 20 |
+
end = time.time()
|
| 21 |
+
time_elapse = end - start
|
| 22 |
+
|
| 23 |
+
return occurrence, time_elapse
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
### configure inputs/outputs
|
| 27 |
+
set_fulltext = gr.inputs.Textbox(label="Full Text")
|
| 28 |
+
set_pattern = gr.inputs.Textbox(label="Pattern")
|
| 29 |
+
set_method = gr.Radio(["Naive-Exact-Match"])
|
| 30 |
+
set_results = gr.outputs.Textbox(label="Occurrence")
|
| 31 |
+
set_times = gr.outputs.Textbox(label="Time elapse")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
### configure gradio, detailed can be found at https://www.gradio.app/docs/#i_slider
|
| 35 |
+
interface = gr.Interface(fn=search_pattern,
|
| 36 |
+
inputs=[set_fulltext, set_pattern,set_method],
|
| 37 |
+
outputs=[set_results,set_times],
|
| 38 |
+
examples_per_page = 2,
|
| 39 |
+
title="CSCI1020 Demo 1: Sequence Match",
|
| 40 |
+
theme = 'huggingface',
|
| 41 |
+
layout = 'vertical'
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
interface.launch(debug=True)
|