Spaces:
Runtime error
Runtime error
File size: 1,511 Bytes
6763efd 2e57a3a 6763efd 2e57a3a 6763efd a880cd2 2e57a3a e448f26 a880cd2 e448f26 29aed29 a880cd2 e448f26 bb2bb24 4cb67e2 6763efd |
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 40 41 42 43 44 45 46 47 |
import gradio as gr
import pyshorteners
def shorten_url(url):
# pyshorteners 라이브러리를 사용하여 URL을 짧게 만드는 함수
shortener = pyshorteners.Shortener()
short_url = shortener.tinyurl.short(url)
return short_url
def url_shortener(url):
# 사용자가 입력한 URL을 받아 짧게 만들고 그 결과를 반환
short_url = shorten_url(url)
return short_url
def clear_inputs():
return "", ""
# Gradio 인터페이스 설정
with gr.Blocks() as iface:
with gr.Row():
with gr.Column():
url_input = gr.Textbox(label="Enter URL")
shorten_button = gr.Button("Shorten URL")
clear_button = gr.Button("Clear")
with gr.Column():
short_url_output = gr.Textbox(label="Shortened URL", copyable=True)
copy_button = gr.Button("Copy to Clipboard")
def update_short_url(url):
short_url = url_shortener(url)
return short_url
shorten_button.click(fn=update_short_url, inputs=url_input, outputs=short_url_output)
clear_button.click(fn=clear_inputs, inputs=[], outputs=[url_input, short_url_output])
copy_button.click(fn=None, _js="""
const shortUrlInput = document.querySelector('input[aria-label="Shortened URL"]');
navigator.clipboard.writeText(shortUrlInput.value).then(() => {
alert('URL copied to clipboard');
}).catch(err => {
console.error('Error copying text: ', err);
});
""")
iface.launch()
|