Spaces:
Sleeping
Sleeping
File size: 1,213 Bytes
a33964b 1ef3b80 a33964b 1ef3b80 a33964b 1ef3b80 a33964b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
import requests
import re
import html
def function(url):
response = requests.get(url)
if response.status_code == 200:
content = response.text
escaped_content = html.escape(content)
print(escaped_content)
pattern = r'APP_INITIALIZATION_STATE=\[\[\[([^]]+)\]'
matches = re.search(pattern, content, re.S)
if matches:
desired_string = matches.group(1)
# Split the string by commas
numbers_list = desired_string.split(',')
# Remove the first element (index 0) from the list
numbers_list = numbers_list[1:]
# Swap the positions of the two numbers in the list
numbers_list[0], numbers_list[1] = numbers_list[1], numbers_list[0]
# Join the remaining elements back into a string using commas as the delimiter
result_string = ','.join(numbers_list)
else:
print("String not found.")
else:
print("Failed to fetch content from the URL.")
return result_string
input = gr.Textbox()
output = gr.Textbox()
interface = gr.Interface(
fn=function,
inputs=input,
outputs=output
)
interface.launch() |