Update app.py
Browse files
app.py
CHANGED
|
@@ -93,6 +93,7 @@ def get_app_py_content(space_id: str) -> str:
|
|
| 93 |
|
| 94 |
def on_select(space):
|
| 95 |
try:
|
|
|
|
| 96 |
summary = summarize_space(space)
|
| 97 |
app_content = get_app_py_content(space['id'])
|
| 98 |
info = f"μ νλ Space: {space['name']} (ID: {space['id']})\n"
|
|
@@ -100,6 +101,7 @@ def on_select(space):
|
|
| 100 |
info += f"Likes: {space['likes']}\n"
|
| 101 |
info += f"URL: {space['url']}\n\n"
|
| 102 |
info += f"μμ½:\n{summary}"
|
|
|
|
| 103 |
return info, app_content, space['url']
|
| 104 |
except Exception as e:
|
| 105 |
print(f"Error in on_select: {str(e)}")
|
|
@@ -107,19 +109,28 @@ def on_select(space):
|
|
| 107 |
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", ""
|
| 108 |
|
| 109 |
def update_screenshot(url, last_url):
|
|
|
|
| 110 |
if url and url != last_url:
|
| 111 |
screenshot = take_screenshot(url)
|
|
|
|
| 112 |
return screenshot, url
|
|
|
|
| 113 |
return gr.update(), last_url
|
| 114 |
|
| 115 |
def take_screenshot(url):
|
| 116 |
try:
|
|
|
|
| 117 |
client = Client("ginipick/selenium-screenshot-gradio")
|
| 118 |
result = client.predict(url=url, api_name="/predict")
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
print(f"Screenshot error: {str(e)}")
|
| 122 |
-
return Image.new('RGB', (
|
| 123 |
|
| 124 |
def create_ui():
|
| 125 |
try:
|
|
@@ -153,7 +164,7 @@ def create_ui():
|
|
| 153 |
last_url_state = gr.State("")
|
| 154 |
|
| 155 |
with gr.Row():
|
| 156 |
-
screenshot_output = gr.Image(type="pil", label="Live νλ©΄", height=360, width=
|
| 157 |
refresh_button = gr.Button("π μλ‘κ³ μΉ¨", scale=0.1)
|
| 158 |
|
| 159 |
app_py_content = gr.Code(language="python", label="λ©μΈ μμ€μ½λ")
|
|
|
|
| 93 |
|
| 94 |
def on_select(space):
|
| 95 |
try:
|
| 96 |
+
print(f"Selected space: {space['name']}")
|
| 97 |
summary = summarize_space(space)
|
| 98 |
app_content = get_app_py_content(space['id'])
|
| 99 |
info = f"μ νλ Space: {space['name']} (ID: {space['id']})\n"
|
|
|
|
| 101 |
info += f"Likes: {space['likes']}\n"
|
| 102 |
info += f"URL: {space['url']}\n\n"
|
| 103 |
info += f"μμ½:\n{summary}"
|
| 104 |
+
print(f"Returning URL: {space['url']}")
|
| 105 |
return info, app_content, space['url']
|
| 106 |
except Exception as e:
|
| 107 |
print(f"Error in on_select: {str(e)}")
|
|
|
|
| 109 |
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", ""
|
| 110 |
|
| 111 |
def update_screenshot(url, last_url):
|
| 112 |
+
print(f"Updating screenshot. Current URL: {url}, Last URL: {last_url}")
|
| 113 |
if url and url != last_url:
|
| 114 |
screenshot = take_screenshot(url)
|
| 115 |
+
print("Screenshot updated")
|
| 116 |
return screenshot, url
|
| 117 |
+
print("No update needed")
|
| 118 |
return gr.update(), last_url
|
| 119 |
|
| 120 |
def take_screenshot(url):
|
| 121 |
try:
|
| 122 |
+
print(f"Attempting to take screenshot of URL: {url}")
|
| 123 |
client = Client("ginipick/selenium-screenshot-gradio")
|
| 124 |
result = client.predict(url=url, api_name="/predict")
|
| 125 |
+
print(f"Screenshot result: {result}")
|
| 126 |
+
if isinstance(result, str) and os.path.exists(result):
|
| 127 |
+
return Image.open(result)
|
| 128 |
+
else:
|
| 129 |
+
print(f"Invalid result from API: {result}")
|
| 130 |
+
return Image.new('RGB', (540, 360), color='lightgray')
|
| 131 |
except Exception as e:
|
| 132 |
print(f"Screenshot error: {str(e)}")
|
| 133 |
+
return Image.new('RGB', (540, 360), color='lightgray')
|
| 134 |
|
| 135 |
def create_ui():
|
| 136 |
try:
|
|
|
|
| 164 |
last_url_state = gr.State("")
|
| 165 |
|
| 166 |
with gr.Row():
|
| 167 |
+
screenshot_output = gr.Image(type="pil", label="Live νλ©΄", height=360, width=600)
|
| 168 |
refresh_button = gr.Button("π μλ‘κ³ μΉ¨", scale=0.1)
|
| 169 |
|
| 170 |
app_py_content = gr.Code(language="python", label="λ©μΈ μμ€μ½λ")
|