Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,31 +86,33 @@ def get_app_py_content(space_id: str) -> str:
|
|
86 |
response = requests.get(app_py_url, headers=get_headers())
|
87 |
if response.status_code == 200:
|
88 |
content = response.text
|
89 |
-
if len(content) >
|
90 |
-
content = content[:
|
91 |
return content
|
92 |
else:
|
93 |
return f"app.py file not found or inaccessible for space: {space_id}"
|
94 |
except requests.RequestException:
|
95 |
return f"Error fetching app.py content for space: {space_id}"
|
96 |
-
|
97 |
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 |
-
|
|
|
108 |
except Exception as e:
|
109 |
print(f"Error in on_select: {str(e)}")
|
110 |
print(traceback.format_exc())
|
111 |
-
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
112 |
|
113 |
def take_screenshot(url):
|
|
|
114 |
try:
|
115 |
chrome_options = Options()
|
116 |
chrome_options.add_argument("--headless")
|
@@ -158,18 +160,15 @@ def create_ui():
|
|
158 |
button = gr.Button("ν΄λ¦", elem_classes="minimal-button")
|
159 |
space_rows.append((space_row, button, space))
|
160 |
|
161 |
-
|
162 |
with gr.Column(scale=1):
|
163 |
-
info_output = gr.Textbox(label="Space μ 보 λ° μμ½", lines=
|
164 |
-
screenshot_output = gr.Image(type="pil", label="Live νλ©΄", height=360, width=540)
|
165 |
app_py_content = gr.Code(language="python", label="app.py λ΄μ©")
|
166 |
|
167 |
-
|
168 |
for _, button, space in space_rows:
|
169 |
-
|
170 |
lambda s=space: on_select(s),
|
171 |
inputs=[],
|
172 |
-
outputs=[info_output,
|
173 |
)
|
174 |
|
175 |
|
|
|
86 |
response = requests.get(app_py_url, headers=get_headers())
|
87 |
if response.status_code == 200:
|
88 |
content = response.text
|
89 |
+
if len(content) > 500: # λ΄μ©μ 500μλ‘ μ νν©λλ€
|
90 |
+
content = content[:497] + "..."
|
91 |
return content
|
92 |
else:
|
93 |
return f"app.py file not found or inaccessible for space: {space_id}"
|
94 |
except requests.RequestException:
|
95 |
return f"Error fetching app.py content for space: {space_id}"
|
96 |
+
|
97 |
def on_select(space):
|
98 |
try:
|
99 |
summary = summarize_space(space)
|
100 |
app_content = get_app_py_content(space['id'])
|
101 |
+
screenshot_info = 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}\n\n"
|
107 |
+
info += f"Screenshot Info: {screenshot_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")
|
|
|
160 |
button = gr.Button("ν΄λ¦", elem_classes="minimal-button")
|
161 |
space_rows.append((space_row, button, space))
|
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 |
|