Update app.py
Browse files
app.py
CHANGED
|
@@ -98,21 +98,19 @@ def on_select(space):
|
|
| 98 |
try:
|
| 99 |
summary = summarize_space(space)
|
| 100 |
app_content = get_app_py_content(space['id'])
|
| 101 |
-
|
| 102 |
info = f"μ νλ Space: {space['name']} (ID: {space['id']})\n"
|
| 103 |
info += f"Author: {space['author']}\n"
|
| 104 |
info += f"Likes: {space['likes']}\n"
|
| 105 |
info += f"URL: {space['url']}\n\n"
|
| 106 |
-
info += f"μμ½:\n{summary}
|
| 107 |
-
info
|
| 108 |
-
return info, app_content
|
| 109 |
except Exception as e:
|
| 110 |
print(f"Error in on_select: {str(e)}")
|
| 111 |
print(traceback.format_exc())
|
| 112 |
-
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
| 113 |
|
| 114 |
def take_screenshot(url):
|
| 115 |
-
return f"Screenshot functionality is disabled. URL: {url}"
|
| 116 |
try:
|
| 117 |
chrome_options = Options()
|
| 118 |
chrome_options.add_argument("--headless")
|
|
@@ -121,7 +119,6 @@ def take_screenshot(url):
|
|
| 121 |
chrome_options.add_argument("--disable-gpu")
|
| 122 |
chrome_options.add_argument("--window-size=1080,720")
|
| 123 |
|
| 124 |
-
# 컨ν
μ΄λ νκ²½μ λ§λ ChromeDriver κ²½λ‘ μ€μ
|
| 125 |
driver = webdriver.Chrome(options=chrome_options)
|
| 126 |
|
| 127 |
driver.get(url)
|
|
@@ -133,7 +130,6 @@ def take_screenshot(url):
|
|
| 133 |
print(f"Screenshot error: {str(e)}")
|
| 134 |
return Image.new('RGB', (1, 1))
|
| 135 |
|
| 136 |
-
|
| 137 |
def create_ui():
|
| 138 |
try:
|
| 139 |
spaces_list = get_most_liked_spaces()
|
|
@@ -162,16 +158,18 @@ def create_ui():
|
|
| 162 |
|
| 163 |
with gr.Column(scale=1):
|
| 164 |
info_output = gr.Textbox(label="Space μ 보 λ° μμ½", lines=20)
|
|
|
|
| 165 |
app_py_content = gr.Code(language="python", label="app.py λ΄μ©")
|
| 166 |
|
| 167 |
for _, button, space in space_rows:
|
| 168 |
button.click(
|
| 169 |
lambda s=space: on_select(s),
|
| 170 |
inputs=[],
|
| 171 |
-
outputs=[info_output, app_py_content]
|
| 172 |
)
|
| 173 |
|
| 174 |
|
|
|
|
| 175 |
return demo
|
| 176 |
|
| 177 |
except Exception as e:
|
|
|
|
| 98 |
try:
|
| 99 |
summary = summarize_space(space)
|
| 100 |
app_content = get_app_py_content(space['id'])
|
| 101 |
+
screenshot = take_screenshot(space['url'])
|
| 102 |
info = f"μ νλ Space: {space['name']} (ID: {space['id']})\n"
|
| 103 |
info += f"Author: {space['author']}\n"
|
| 104 |
info += f"Likes: {space['likes']}\n"
|
| 105 |
info += f"URL: {space['url']}\n\n"
|
| 106 |
+
info += f"μμ½:\n{summary}"
|
| 107 |
+
return info, app_content, screenshot
|
|
|
|
| 108 |
except Exception as e:
|
| 109 |
print(f"Error in on_select: {str(e)}")
|
| 110 |
print(traceback.format_exc())
|
| 111 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", Image.new('RGB', (1, 1))
|
| 112 |
|
| 113 |
def take_screenshot(url):
|
|
|
|
| 114 |
try:
|
| 115 |
chrome_options = Options()
|
| 116 |
chrome_options.add_argument("--headless")
|
|
|
|
| 119 |
chrome_options.add_argument("--disable-gpu")
|
| 120 |
chrome_options.add_argument("--window-size=1080,720")
|
| 121 |
|
|
|
|
| 122 |
driver = webdriver.Chrome(options=chrome_options)
|
| 123 |
|
| 124 |
driver.get(url)
|
|
|
|
| 130 |
print(f"Screenshot error: {str(e)}")
|
| 131 |
return Image.new('RGB', (1, 1))
|
| 132 |
|
|
|
|
| 133 |
def create_ui():
|
| 134 |
try:
|
| 135 |
spaces_list = get_most_liked_spaces()
|
|
|
|
| 158 |
|
| 159 |
with gr.Column(scale=1):
|
| 160 |
info_output = gr.Textbox(label="Space μ 보 λ° μμ½", lines=20)
|
| 161 |
+
screenshot_output = gr.Image(type="pil", label="Live νλ©΄", height=360, width=540)
|
| 162 |
app_py_content = gr.Code(language="python", label="app.py λ΄μ©")
|
| 163 |
|
| 164 |
for _, button, space in space_rows:
|
| 165 |
button.click(
|
| 166 |
lambda s=space: on_select(s),
|
| 167 |
inputs=[],
|
| 168 |
+
outputs=[info_output, app_py_content, screenshot_output]
|
| 169 |
)
|
| 170 |
|
| 171 |
|
| 172 |
+
|
| 173 |
return demo
|
| 174 |
|
| 175 |
except Exception as e:
|