Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ async def fetch_messages(channel_username):
|
|
| 23 |
'date': str(message.date),
|
| 24 |
'forwarded_from': message.forward.sender.username if message.forward else None
|
| 25 |
})
|
|
|
|
| 26 |
return messages
|
| 27 |
except Exception as e:
|
| 28 |
print(f"Error fetching messages: {str(e)}")
|
|
@@ -46,13 +47,19 @@ def visualize_network(channel_username):
|
|
| 46 |
messages = asyncio.run(fetch_messages(channel_username))
|
| 47 |
|
| 48 |
if not messages: # Si no hay mensajes, devuelve un gr谩fico vac铆o
|
| 49 |
-
G = nx.DiGraph()
|
| 50 |
plt.figure(figsize=(10, 8))
|
| 51 |
-
plt.title("No data available")
|
|
|
|
| 52 |
return plt.gcf()
|
| 53 |
|
| 54 |
G = build_network(messages)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
plt.figure(figsize=(10, 8))
|
| 57 |
pos = nx.spring_layout(G)
|
| 58 |
nx.draw(G, pos, with_labels=True, node_size=3000, node_color='lightblue', font_size=10, font_weight='bold')
|
|
@@ -64,6 +71,7 @@ def visualize_network(channel_username):
|
|
| 64 |
print(f"Error in visualize_network: {str(e)}")
|
| 65 |
plt.figure(figsize=(10, 8))
|
| 66 |
plt.title("An error occurred")
|
|
|
|
| 67 |
return plt.gcf()
|
| 68 |
|
| 69 |
# Interfaz de Gradio
|
|
|
|
| 23 |
'date': str(message.date),
|
| 24 |
'forwarded_from': message.forward.sender.username if message.forward else None
|
| 25 |
})
|
| 26 |
+
print(f"Messages fetched: {len(messages)}") # Mensaje de depuraci贸n
|
| 27 |
return messages
|
| 28 |
except Exception as e:
|
| 29 |
print(f"Error fetching messages: {str(e)}")
|
|
|
|
| 47 |
messages = asyncio.run(fetch_messages(channel_username))
|
| 48 |
|
| 49 |
if not messages: # Si no hay mensajes, devuelve un gr谩fico vac铆o
|
|
|
|
| 50 |
plt.figure(figsize=(10, 8))
|
| 51 |
+
plt.title("No data available for this channel")
|
| 52 |
+
plt.text(0.5, 0.5, "Try another channel or check the username.", fontsize=12, ha='center')
|
| 53 |
return plt.gcf()
|
| 54 |
|
| 55 |
G = build_network(messages)
|
| 56 |
|
| 57 |
+
if G.number_of_edges() == 0: # Si no hay aristas, muestra un mensaje
|
| 58 |
+
plt.figure(figsize=(10, 8))
|
| 59 |
+
plt.title("No forwarding patterns found")
|
| 60 |
+
plt.text(0.5, 0.5, "This channel has no forwarded messages.", fontsize=12, ha='center')
|
| 61 |
+
return plt.gcf()
|
| 62 |
+
|
| 63 |
plt.figure(figsize=(10, 8))
|
| 64 |
pos = nx.spring_layout(G)
|
| 65 |
nx.draw(G, pos, with_labels=True, node_size=3000, node_color='lightblue', font_size=10, font_weight='bold')
|
|
|
|
| 71 |
print(f"Error in visualize_network: {str(e)}")
|
| 72 |
plt.figure(figsize=(10, 8))
|
| 73 |
plt.title("An error occurred")
|
| 74 |
+
plt.text(0.5, 0.5, "Please check the logs for more details.", fontsize=12, ha='center')
|
| 75 |
return plt.gcf()
|
| 76 |
|
| 77 |
# Interfaz de Gradio
|