Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -139,107 +139,6 @@ def take_screenshot(url):
|
|
139 |
print(f"Screenshot error: {str(e)}")
|
140 |
return Image.new('RGB', (600, 360), color='lightgray')
|
141 |
|
142 |
-
def create_ui():
|
143 |
-
try:
|
144 |
-
spaces_list = get_most_liked_spaces()
|
145 |
-
formatted_spaces = format_spaces(spaces_list)
|
146 |
-
print(f"Total spaces loaded: {len(formatted_spaces)}")
|
147 |
-
|
148 |
-
css = """
|
149 |
-
footer {visibility: hidden;}
|
150 |
-
.minimal-button {min-width: 30px !important; height: 25px !important; line-height: 1 !important; font-size: 12px !important; padding: 2px 5px !important;}
|
151 |
-
.space-row {margin-bottom: 5px !important;}
|
152 |
-
#refresh-button, #manual-button {
|
153 |
-
width: 100% !important;
|
154 |
-
margin-top: 5px !important;
|
155 |
-
}
|
156 |
-
#usage-guide {
|
157 |
-
height: 300px;
|
158 |
-
overflow-y: auto;
|
159 |
-
}
|
160 |
-
#app-py-content {
|
161 |
-
height: auto;
|
162 |
-
max-height: none;
|
163 |
-
}
|
164 |
-
"""
|
165 |
-
|
166 |
-
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
167 |
-
gr.Markdown("# 300: HuggingFace Most Liked Spaces")
|
168 |
-
|
169 |
-
with gr.Row():
|
170 |
-
with gr.Column(scale=1):
|
171 |
-
space_rows = []
|
172 |
-
for space in formatted_spaces:
|
173 |
-
with gr.Row(elem_classes="space-row") as space_row:
|
174 |
-
with gr.Column():
|
175 |
-
gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})", elem_classes="space-info")
|
176 |
-
button = gr.Button("ํด๋ฆญ", elem_classes="minimal-button")
|
177 |
-
space_rows.append((space_row, button, space))
|
178 |
-
|
179 |
-
with gr.Column(scale=1):
|
180 |
-
info_output = gr.Textbox(label="Space ์ ๋ณด ๋ฐ ์์ฝ", lines=20)
|
181 |
-
url_state = gr.State("")
|
182 |
-
last_url_state = gr.State("")
|
183 |
-
|
184 |
-
screenshot_output = gr.Image(type="pil", label="Live ํ๋ฉด", height=360, width=600)
|
185 |
-
refresh_button = gr.Button("๐ ์๋ก๊ณ ์นจ", elem_id="refresh-button")
|
186 |
-
manual_button = gr.Button("์ ํ ์๋น์ค ๋ฉ๋ด์ผ", elem_id="manual-button")
|
187 |
-
|
188 |
-
usage_guide = gr.Textbox(label="์ฌ์ฉ ๋ฐฉ๋ฒ", elem_id="usage-guide", visible=False, lines=20)
|
189 |
-
app_py_content = gr.Code(language="python", label="๋ฉ์ธ ์์ค์ฝ๋", elem_id="app-py-content")
|
190 |
-
update_trigger = gr.Button("Update Screenshot", visible=False)
|
191 |
-
|
192 |
-
for _, button, space in space_rows:
|
193 |
-
button.click(
|
194 |
-
lambda s=space: on_select(s),
|
195 |
-
inputs=[],
|
196 |
-
outputs=[info_output, app_py_content, url_state]
|
197 |
-
).then(
|
198 |
-
update_screenshot,
|
199 |
-
inputs=[url_state, last_url_state],
|
200 |
-
outputs=[screenshot_output, last_url_state]
|
201 |
-
)
|
202 |
-
|
203 |
-
def refresh_screenshot(url, last_url):
|
204 |
-
print(f"Refresh button clicked. URL: {url}, Last URL: {last_url}")
|
205 |
-
return update_screenshot(url, last_url)
|
206 |
-
|
207 |
-
refresh_button.click(
|
208 |
-
refresh_screenshot,
|
209 |
-
inputs=[url_state, last_url_state],
|
210 |
-
outputs=[screenshot_output, last_url_state]
|
211 |
-
)
|
212 |
-
|
213 |
-
def show_usage_guide(app_content):
|
214 |
-
usage_text = generate_usage_guide(app_content)
|
215 |
-
return gr.update(value=usage_text, visible=True)
|
216 |
-
|
217 |
-
manual_button.click(
|
218 |
-
show_usage_guide,
|
219 |
-
inputs=[app_py_content],
|
220 |
-
outputs=[usage_guide]
|
221 |
-
)
|
222 |
-
|
223 |
-
update_trigger.click(
|
224 |
-
update_screenshot,
|
225 |
-
inputs=[url_state, last_url_state],
|
226 |
-
outputs=[screenshot_output, last_url_state]
|
227 |
-
)
|
228 |
-
|
229 |
-
# Start a background thread to trigger updates
|
230 |
-
def trigger_updates():
|
231 |
-
while True:
|
232 |
-
time.sleep(5)
|
233 |
-
update_trigger.click()
|
234 |
-
|
235 |
-
threading.Thread(target=trigger_updates, daemon=True).start()
|
236 |
-
|
237 |
-
return demo
|
238 |
-
|
239 |
-
except Exception as e:
|
240 |
-
print(f"Error in create_ui: {str(e)}")
|
241 |
-
print(traceback.format_exc())
|
242 |
-
raise
|
243 |
|
244 |
def generate_usage_guide(app_content):
|
245 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ๊ทธ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ ๊ณตํด์ฃผ์ธ์."
|
@@ -254,7 +153,9 @@ def generate_usage_guide(app_content):
|
|
254 |
response = hf_client.chat_completion(messages, max_tokens=4000, temperature=0.7)
|
255 |
return response.choices[0].message.content
|
256 |
except Exception as e:
|
257 |
-
return f"์ฌ์ฉ ๋ฐฉ๋ฒ
|
|
|
|
|
258 |
try:
|
259 |
spaces_list = get_most_liked_spaces()
|
260 |
formatted_spaces = format_spaces(spaces_list)
|
@@ -356,21 +257,6 @@ def generate_usage_guide(app_content):
|
|
356 |
print(traceback.format_exc())
|
357 |
raise
|
358 |
|
359 |
-
def generate_usage_guide(app_content):
|
360 |
-
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ๊ทธ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ ๊ณตํด์ฃผ์ธ์."
|
361 |
-
user_message = f"๋ค์ Python ์ฝ๋์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ค๋ช
ํด์ฃผ์ธ์:\n\n{app_content}"
|
362 |
-
|
363 |
-
messages = [
|
364 |
-
{"role": "system", "content": system_message},
|
365 |
-
{"role": "user", "content": user_message}
|
366 |
-
]
|
367 |
-
|
368 |
-
try:
|
369 |
-
response = hf_client.chat_completion(messages, max_tokens=4000, temperature=0.7)
|
370 |
-
return response.choices[0].message.content
|
371 |
-
except Exception as e:
|
372 |
-
return f"์ฌ์ฉ ๋ฐฉ๋ฒ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
373 |
-
|
374 |
if __name__ == "__main__":
|
375 |
try:
|
376 |
demo = create_ui()
|
|
|
139 |
print(f"Screenshot error: {str(e)}")
|
140 |
return Image.new('RGB', (600, 360), color='lightgray')
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
def generate_usage_guide(app_content):
|
144 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ๊ทธ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ ๊ณตํด์ฃผ์ธ์."
|
|
|
153 |
response = hf_client.chat_completion(messages, max_tokens=4000, temperature=0.7)
|
154 |
return response.choices[0].message.content
|
155 |
except Exception as e:
|
156 |
+
return f"์ฌ์ฉ ๋ฐฉ๋ฒ ๏ฟฝ๏ฟฝ์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
157 |
+
|
158 |
+
def create_ui():
|
159 |
try:
|
160 |
spaces_list = get_most_liked_spaces()
|
161 |
formatted_spaces = format_spaces(spaces_list)
|
|
|
257 |
print(traceback.format_exc())
|
258 |
raise
|
259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
if __name__ == "__main__":
|
261 |
try:
|
262 |
demo = create_ui()
|