Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def search_pattern(fulltext, pattern, method): | |
| fulltext = fulltext.replace('\n','') | |
| pattern = pattern.replace('\n','') | |
| if method == 'Naive-Exact-Match': | |
| import time | |
| start = time.time() | |
| occurrence = 0 | |
| for i in range(0,len(fulltext)-len(pattern)+1): | |
| found = 1 | |
| for l in range(len(pattern)): | |
| if fulltext[i+l] != pattern[l]: | |
| found = 0 | |
| if found: | |
| occurrence += 1 | |
| print("Found ", fulltext[i:i+len(pattern)], ' locating at position ', i+1) | |
| end = time.time() | |
| time_elapse = end - start | |
| return occurrence, time_elapse | |
| ### configure inputs/outputs | |
| set_fulltext = gr.inputs.Textbox(label="Full Text") | |
| set_pattern = gr.inputs.Textbox(label="Pattern") | |
| set_method = gr.Radio(["Naive-Exact-Match"]) | |
| set_results = gr.outputs.Textbox(label="Occurrence") | |
| set_times = gr.outputs.Textbox(label="Time elapse") | |
| ### configure gradio, detailed can be found at https://www.gradio.app/docs/#i_slider | |
| interface = gr.Interface(fn=search_pattern, | |
| inputs=[set_fulltext, set_pattern,set_method], | |
| outputs=[set_results,set_times], | |
| examples_per_page = 2, | |
| title="CSCI1020 Demo 1: Sequence Match", | |
| theme = 'huggingface', | |
| layout = 'vertical' | |
| ) | |
| interface.launch(debug=True) |