Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -177,6 +177,28 @@ async def fetch_space_file_content(space_url, file_path):
|
|
177 |
except Exception as e:
|
178 |
return f"Error: {e}"
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
# Create the Gradio interface
|
181 |
with gr.Blocks() as demo:
|
182 |
gr.HTML(copy_button_html) # Add the "Copy Code" script
|
@@ -279,5 +301,30 @@ with gr.Blocks() as demo:
|
|
279 |
outputs=[space_content_output]
|
280 |
)
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
# Launch the interface
|
283 |
demo.launch()
|
|
|
177 |
except Exception as e:
|
178 |
return f"Error: {e}"
|
179 |
|
180 |
+
# CodePen to Text Converter
|
181 |
+
async def fetch_codepen_project(codepen_url):
|
182 |
+
"""Fetches the HTML, CSS, and JavaScript content from a CodePen project."""
|
183 |
+
try:
|
184 |
+
# Extract the project ID from the URL
|
185 |
+
if "codepen.io" not in codepen_url:
|
186 |
+
return "Error: Please enter a valid CodePen URL.", "", ""
|
187 |
+
|
188 |
+
# Fetch the CodePen project page
|
189 |
+
response = await asyncio.to_thread(requests.get, codepen_url, timeout=5)
|
190 |
+
response.raise_for_status()
|
191 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
192 |
+
|
193 |
+
# Extract HTML, CSS, and JS content
|
194 |
+
html_content = soup.find("textarea", {"id": "html-input"}).text if soup.find("textarea", {"id": "html-input"}) else ""
|
195 |
+
css_content = soup.find("textarea", {"id": "css-input"}).text if soup.find("textarea", {"id": "css-input"}) else ""
|
196 |
+
js_content = soup.find("textarea", {"id": "js-input"}).text if soup.find("textarea", {"id": "js-input"}) else ""
|
197 |
+
|
198 |
+
return html_content, css_content, js_content
|
199 |
+
except Exception as e:
|
200 |
+
return f"Error: {e}", "", ""
|
201 |
+
|
202 |
# Create the Gradio interface
|
203 |
with gr.Blocks() as demo:
|
204 |
gr.HTML(copy_button_html) # Add the "Copy Code" script
|
|
|
301 |
outputs=[space_content_output]
|
302 |
)
|
303 |
|
304 |
+
# Tab 4: CodePen to Text Converter
|
305 |
+
with gr.Tab("CodePen to Text Converter"):
|
306 |
+
gr.Markdown("## CodePen to Text Converter")
|
307 |
+
gr.Markdown("Enter a CodePen project URL to fetch its HTML, CSS, and JavaScript content.")
|
308 |
+
|
309 |
+
with gr.Row():
|
310 |
+
codepen_url_input = gr.Textbox(label="CodePen URL", placeholder="https://codepen.io/.../pen/...")
|
311 |
+
|
312 |
+
with gr.Row():
|
313 |
+
html_output = gr.Textbox(label="HTML Content", interactive=True, elem_id="html-output")
|
314 |
+
css_output = gr.Textbox(label="CSS Content", interactive=True, elem_id="css-output")
|
315 |
+
js_output = gr.Textbox(label="JavaScript Content", interactive=True, elem_id="js-output")
|
316 |
+
|
317 |
+
with gr.Row():
|
318 |
+
gr.HTML("<button onclick='copyCode(\"html-output\")'>Copy HTML</button>")
|
319 |
+
gr.HTML("<button onclick='copyCode(\"css-output\")'>Copy CSS</button>")
|
320 |
+
gr.HTML("<button onclick='copyCode(\"js-output\")'>Copy JS</button>")
|
321 |
+
|
322 |
+
submit_codepen_button = gr.Button("Fetch CodePen Content")
|
323 |
+
submit_codepen_button.click(
|
324 |
+
fn=fetch_codepen_project,
|
325 |
+
inputs=[codepen_url_input],
|
326 |
+
outputs=[html_output, css_output, js_output]
|
327 |
+
)
|
328 |
+
|
329 |
# Launch the interface
|
330 |
demo.launch()
|