Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests # requests ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ
|
| 3 |
+
|
| 4 |
+
def execute_get_request(token, virtual):
|
| 5 |
+
"""Generates a GET request URL for Blynk API and executes the request."""
|
| 6 |
+
url = "https://blynk.cloud/external/api/get?token=" + token + '&' + virtual
|
| 7 |
+
try:
|
| 8 |
+
response = requests.get(url)
|
| 9 |
+
response.raise_for_status() # ์๋ฌ ๋ฐ์ ์ HTTPError ์์ธ ๋ฐ์
|
| 10 |
+
response_text = response.text # ์๋ต ํ
์คํธ ์ถ์ถ
|
| 11 |
+
except requests.exceptions.RequestException as e:
|
| 12 |
+
response_text = f"์์ฒญ ์คํจ: {e}" # ์๋ฌ ๋ฉ์์ง
|
| 13 |
+
return url, response_text # URL๊ณผ ์๋ต ํ
์คํธ ๋ฐํ
|
| 14 |
+
|
| 15 |
+
def create_push_url(token, virtual,value):
|
| 16 |
+
"""Generates a PUSH request URL for Blynk API."""
|
| 17 |
+
url = "https://blynk.cloud/external/api/update?token=" + token + '&' + virtual + '=' + str(value)
|
| 18 |
+
try:
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
response.raise_for_status() # ์๋ฌ ๋ฐ์ ์ HTTPError ์์ธ ๋ฐ์
|
| 21 |
+
response_text = response.text # ์๋ต ํ
์คํธ ์ถ์ถ
|
| 22 |
+
except requests.exceptions.RequestException as e:
|
| 23 |
+
response_text = f"์์ฒญ ์คํจ: {e}" # ์๋ฌ ๋ฉ์์ง
|
| 24 |
+
return url
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("# Blynk ์ฝ๊ฒ ์ฌ์ฉํ๋ ์น์ฑ")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
with gr.Column():
|
| 31 |
+
gr.Markdown("### ๊ฐ ๊ฐ์ ธ์ค๊ธฐ (GET)") # Section title for GET
|
| 32 |
+
get_token_textbox = gr.Textbox(label='ํ ํฐ ๊ฐ (Token Value):') # Input for GET Token
|
| 33 |
+
get_virtual_pin_radio = gr.Radio(['V0','V1','V2','V3','V4'], label='Virtual Pin ์ ํ (Virtual Pin Selection):') # Radio for GET Virtual Pin
|
| 34 |
+
generate_get_url_button = gr.Button("GET ์์ฒญ ์คํ (Execute GET Request)") # Button to trigger GET request (๋ฒํผ ์ด๋ฆ ๋ณ๊ฒฝ)
|
| 35 |
+
get_url_output_textbox = gr.Textbox(label='์์ฑ๋ GET URL (Generated GET URL):',show_copy_button=True) # Output textbox for GET URL
|
| 36 |
+
get_response_textbox = gr.Textbox(label='GET ์๋ต (GET Response):',show_copy_button=True) # ์๋ต ํ
์คํธ๋ฅผ ๋ณด์ฌ์ค ํ
์คํธ ๋ฐ์ค ์ถ๊ฐ
|
| 37 |
+
|
| 38 |
+
generate_get_url_button.click(
|
| 39 |
+
fn=execute_get_request, # ํจ์ ์ด๋ฆ ๋ณ๊ฒฝ (์์ฒญ ์คํ ํจ์๋ก ๋ณ๊ฒฝ)
|
| 40 |
+
inputs=[get_token_textbox, get_virtual_pin_radio],
|
| 41 |
+
outputs=[get_url_output_textbox, get_response_textbox] # outputs์ ์๋ต ํ
์คํธ ๋ฐ์ค ์ถ๊ฐ
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
gr.Markdown("### ๊ฐ ์ค์ (PUSH)") # Section title for PUSH
|
| 46 |
+
push_token_textbox = gr.Textbox(label='ํ ํฐ ๊ฐ (Token Value):') # Input for PUSH Token
|
| 47 |
+
push_virtual_pin_radio = gr.Radio(['V0','V1','V2','V3','V4'], label='Virtual Pin ์ ํ (Virtual Pin Selection):') # Radio for PUSH Virtual Pin
|
| 48 |
+
push_value = gr.Slider(1, 255, label='Virtual Pin ๊ฐ ์ ํ')
|
| 49 |
+
generate_push_url_button = gr.Button("PUSH URL ์์ฑ (Generate PUSH URL)") # Button to trigger PUSH URL generation
|
| 50 |
+
push_url_output_textbox = gr.Textbox(label='์์ฑ๋ PUSH URL (Generated PUSH URL):',show_copy_button=True) # Output textbox for PUSH URL
|
| 51 |
+
|
| 52 |
+
generate_push_url_button.click(
|
| 53 |
+
fn=create_push_url, # PUSH URL ์์ฑ ํจ์๋ ๊ทธ๋๋ก ์ฌ์ฉ
|
| 54 |
+
inputs=[push_token_textbox, push_virtual_pin_radio,push_value],
|
| 55 |
+
outputs=push_url_output_textbox
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
demo.launch()
|