Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import requests
|
|
3 |
from urllib.parse import urlparse, urljoin
|
4 |
from bs4 import BeautifulSoup
|
5 |
import asyncio
|
6 |
-
import subprocess
|
7 |
|
8 |
# HTML and JavaScript for the "Copy Code" button
|
9 |
copy_button_html = """
|
@@ -174,38 +173,28 @@ async def fetch_space_file_content(space_url, file_path):
|
|
174 |
except Exception as e:
|
175 |
return f"Error: {e}"
|
176 |
|
177 |
-
#
|
178 |
-
def
|
179 |
-
"""
|
180 |
try:
|
181 |
-
#
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
parts = line.split(":")
|
198 |
-
if len(parts) >= 4:
|
199 |
-
file_name, line_number, column, message = parts[0], parts[1], parts[2], ":".join(parts[3:])
|
200 |
-
error_messages.append(f"Line {line_number}, Column {column}: {message.strip()}")
|
201 |
-
|
202 |
-
if not error_messages:
|
203 |
-
return "Errors found, but could not parse details.", code
|
204 |
-
|
205 |
-
detailed_feedback = "Errors found in the code:\n" + "\n".join(error_messages)
|
206 |
-
return detailed_feedback, code
|
207 |
except Exception as e:
|
208 |
-
return f"Error: {e}"
|
209 |
|
210 |
# Create the Gradio interface
|
211 |
with gr.Blocks() as demo:
|
@@ -256,17 +245,6 @@ with gr.Blocks() as demo:
|
|
256 |
gr.Markdown("### JS Content")
|
257 |
js_content_output = gr.Textbox(label="JS Content", interactive=True)
|
258 |
|
259 |
-
# Add image previews
|
260 |
-
gr.Markdown("### Image Previews")
|
261 |
-
image_previews = gr.Gallery(label="Image Previews")
|
262 |
-
|
263 |
-
# Update the image previews
|
264 |
-
submit_button.click(
|
265 |
-
fn=lambda img_links: [requests.get(link).content for link in img_links],
|
266 |
-
inputs=img_output,
|
267 |
-
outputs=image_previews
|
268 |
-
)
|
269 |
-
|
270 |
# Tab 2: Model to Text Converter
|
271 |
with gr.Tab("Model to Text Converter"):
|
272 |
gr.Markdown("## Model to Text Converter")
|
@@ -313,20 +291,6 @@ with gr.Blocks() as demo:
|
|
313 |
with gr.Row():
|
314 |
gr.HTML("<button onclick='copyCode(\"space-content-output\")'>Copy Code</button>") # Add the "Copy Code" button
|
315 |
|
316 |
-
# Кнопка Correcter
|
317 |
-
correcter_button = gr.Button("Correcter")
|
318 |
-
|
319 |
-
# Обработчик для кнопки Correcter
|
320 |
-
def correct_code_handler(code):
|
321 |
-
result, corrected_code = check_code_for_errors(code)
|
322 |
-
return result, corrected_code
|
323 |
-
|
324 |
-
correcter_button.click(
|
325 |
-
fn=correct_code_handler,
|
326 |
-
inputs=space_content_output,
|
327 |
-
outputs=[gr.Textbox(label="Correction Result"), space_content_output]
|
328 |
-
)
|
329 |
-
|
330 |
submit_space_button = gr.Button("Fetch File Content")
|
331 |
submit_space_button.click(
|
332 |
fn=fetch_space_file_content,
|
@@ -334,5 +298,26 @@ with gr.Blocks() as demo:
|
|
334 |
outputs=[space_content_output]
|
335 |
)
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
# Launch the interface
|
338 |
demo.launch()
|
|
|
3 |
from urllib.parse import urlparse, urljoin
|
4 |
from bs4 import BeautifulSoup
|
5 |
import asyncio
|
|
|
6 |
|
7 |
# HTML and JavaScript for the "Copy Code" button
|
8 |
copy_button_html = """
|
|
|
173 |
except Exception as e:
|
174 |
return f"Error: {e}"
|
175 |
|
176 |
+
# Perchance to Text Converter
|
177 |
+
async def fetch_perchance_text(perchance_url):
|
178 |
+
"""Fetches the text content from a Perchance application."""
|
179 |
try:
|
180 |
+
# Fetch the HTML content of the Perchance page
|
181 |
+
response = await asyncio.to_thread(requests.get, perchance_url, timeout=5)
|
182 |
+
response.raise_for_status()
|
183 |
+
|
184 |
+
# Parse the HTML content
|
185 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
186 |
+
|
187 |
+
# Extract the text content of the Perchance application
|
188 |
+
# Assuming the main content is inside a <div> with a specific class or id
|
189 |
+
# You may need to inspect the page to find the correct selector
|
190 |
+
main_content = soup.find("div", {"class": "perchance-app"}) # Adjust the selector as needed
|
191 |
+
|
192 |
+
if main_content:
|
193 |
+
return main_content.get_text(strip=True)
|
194 |
+
else:
|
195 |
+
return "Error: Could not find the Perchance application content."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
except Exception as e:
|
197 |
+
return f"Error: {e}"
|
198 |
|
199 |
# Create the Gradio interface
|
200 |
with gr.Blocks() as demo:
|
|
|
245 |
gr.Markdown("### JS Content")
|
246 |
js_content_output = gr.Textbox(label="JS Content", interactive=True)
|
247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
# Tab 2: Model to Text Converter
|
249 |
with gr.Tab("Model to Text Converter"):
|
250 |
gr.Markdown("## Model to Text Converter")
|
|
|
291 |
with gr.Row():
|
292 |
gr.HTML("<button onclick='copyCode(\"space-content-output\")'>Copy Code</button>") # Add the "Copy Code" button
|
293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
submit_space_button = gr.Button("Fetch File Content")
|
295 |
submit_space_button.click(
|
296 |
fn=fetch_space_file_content,
|
|
|
298 |
outputs=[space_content_output]
|
299 |
)
|
300 |
|
301 |
+
# Tab 4: Perchance to Text Converter
|
302 |
+
with gr.Tab("Perchance to Text Converter"):
|
303 |
+
gr.Markdown("## Perchance to Text Converter")
|
304 |
+
gr.Markdown("Enter a link to a Perchance application to fetch its text content.")
|
305 |
+
|
306 |
+
with gr.Row():
|
307 |
+
perchance_url_input = gr.Textbox(label="Perchance URL", placeholder="https://perchance.org/...")
|
308 |
+
|
309 |
+
with gr.Row():
|
310 |
+
perchance_content_output = gr.Textbox(label="Text Content", interactive=True, elem_id="perchance-content-output")
|
311 |
+
|
312 |
+
with gr.Row():
|
313 |
+
gr.HTML("<button onclick='copyCode(\"perchance-content-output\")'>Copy Code</button>") # Add the "Copy Code" button
|
314 |
+
|
315 |
+
submit_perchance_button = gr.Button("Fetch Text Content")
|
316 |
+
submit_perchance_button.click(
|
317 |
+
fn=fetch_perchance_text,
|
318 |
+
inputs=perchance_url_input,
|
319 |
+
outputs=perchance_content_output
|
320 |
+
)
|
321 |
+
|
322 |
# Launch the interface
|
323 |
demo.launch()
|