Spaces:
Running
on
Zero
Running
on
Zero
Minor improvements
Browse files- app.py +9 -10
- download_url.py +1 -0
app.py
CHANGED
|
@@ -54,6 +54,15 @@ def generate_text(
|
|
| 54 |
) -> (str, str):
|
| 55 |
global cache_handler
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# 1) Download the article
|
| 58 |
|
| 59 |
progress(0, desc="🤖 Accediendo a la noticia")
|
|
@@ -72,11 +81,6 @@ def generate_text(
|
|
| 72 |
text = None
|
| 73 |
|
| 74 |
if title is None or text is None:
|
| 75 |
-
yield (
|
| 76 |
-
"🤖 No he podido acceder a la notica, asegurate que la URL es correcta y que es posible acceder a la noticia desde un navegador.",
|
| 77 |
-
"❌❌❌ Inténtalo de nuevo ❌❌❌",
|
| 78 |
-
"Error",
|
| 79 |
-
)
|
| 80 |
return (
|
| 81 |
"🤖 No he podido acceder a la notica, asegurate que la URL es correcta y que es posible acceder a la noticia desde un navegador.",
|
| 82 |
"❌❌❌ Inténtalo de nuevo ❌❌❌",
|
|
@@ -105,11 +109,6 @@ def generate_text(
|
|
| 105 |
yield title, o, text
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
-
yield (
|
| 109 |
-
"🤖 El servidor no se encuentra disponible.",
|
| 110 |
-
"❌❌❌ Inténtalo de nuevo más tarde ❌❌❌",
|
| 111 |
-
"Error",
|
| 112 |
-
)
|
| 113 |
return (
|
| 114 |
"🤖 El servidor no se encuentra disponible.",
|
| 115 |
"❌❌❌ Inténtalo de nuevo más tarde ❌❌❌",
|
|
|
|
| 54 |
) -> (str, str):
|
| 55 |
global cache_handler
|
| 56 |
|
| 57 |
+
url = url.strip()
|
| 58 |
+
|
| 59 |
+
if url.startswith("https://twitter.com/") or url.startswith("https://x.com/"):
|
| 60 |
+
return (
|
| 61 |
+
"🤖 Vaya, parece que has introducido la url de un tweet. No puedo acceder a tweets, tienes que introducir la URL de una noticia.",
|
| 62 |
+
"❌❌❌ Si el tweet contiene una noticia, dame la URL de la noticia ❌❌❌",
|
| 63 |
+
"Error",
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
# 1) Download the article
|
| 67 |
|
| 68 |
progress(0, desc="🤖 Accediendo a la noticia")
|
|
|
|
| 81 |
text = None
|
| 82 |
|
| 83 |
if title is None or text is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
return (
|
| 85 |
"🤖 No he podido acceder a la notica, asegurate que la URL es correcta y que es posible acceder a la noticia desde un navegador.",
|
| 86 |
"❌❌❌ Inténtalo de nuevo ❌❌❌",
|
|
|
|
| 109 |
yield title, o, text
|
| 110 |
|
| 111 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
return (
|
| 113 |
"🤖 El servidor no se encuentra disponible.",
|
| 114 |
"❌❌❌ Inténtalo de nuevo más tarde ❌❌❌",
|
download_url.py
CHANGED
|
@@ -5,6 +5,7 @@ from bs4 import BeautifulSoup
|
|
| 5 |
def download_text_and_title(url):
|
| 6 |
try:
|
| 7 |
# Remove the query string from the URL
|
|
|
|
| 8 |
url = url.split("?")[0]
|
| 9 |
# Remove emojis and other special characters
|
| 10 |
url = url.encode("ascii", "ignore").decode("ascii")
|
|
|
|
| 5 |
def download_text_and_title(url):
|
| 6 |
try:
|
| 7 |
# Remove the query string from the URL
|
| 8 |
+
url = url.strip()
|
| 9 |
url = url.split("?")[0]
|
| 10 |
# Remove emojis and other special characters
|
| 11 |
url = url.encode("ascii", "ignore").decode("ascii")
|