Delete app.py
Browse files
app.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import fitz # PyMuPDF
|
3 |
-
import requests
|
4 |
-
from graphviz import Digraph
|
5 |
-
|
6 |
-
# Function to extract text from a PDF
|
7 |
-
def extract_text_from_pdf(pdf_file):
|
8 |
-
pdf_document = fitz.open(stream=pdf_file.read(), filetype="pdf")
|
9 |
-
text = ""
|
10 |
-
for page in pdf_document:
|
11 |
-
text += page.get_text()
|
12 |
-
pdf_document.close()
|
13 |
-
return text
|
14 |
-
|
15 |
-
# Function to search images via Wikipedia API
|
16 |
-
def search_images(query):
|
17 |
-
url = f"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={query}&format=json"
|
18 |
-
response = requests.get(url)
|
19 |
-
data = response.json()
|
20 |
-
images = []
|
21 |
-
for item in data['query']['search']:
|
22 |
-
title = item['title']
|
23 |
-
img_url = f"https://en.wikipedia.org/wiki/File:{title.replace(' ', '_')}.png"
|
24 |
-
images.append(img_url)
|
25 |
-
return images
|
26 |
-
|
27 |
-
# Function to create a mind map
|
28 |
-
def create_mind_map(text, images):
|
29 |
-
dot = Digraph()
|
30 |
-
dot.node('A', 'Concept Central', shape='box', style='filled', fillcolor='lightblue')
|
31 |
-
for i, img in enumerate(images):
|
32 |
-
node_label = text[i] if i < len(text) else 'Other'
|
33 |
-
dot.node(f'B{i}', node_label, shape='ellipse', style='filled', fillcolor='lightyellow')
|
34 |
-
dot.edge('A', f'B{i}', label=f'Image {i+1}')
|
35 |
-
dot.node(f'C{i}', img, image=img, shape='rect')
|
36 |
-
dot.edge(f'B{i}', f'C{i}')
|
37 |
-
return dot
|
38 |
-
|
39 |
-
# Streamlit app initialization
|
40 |
-
st.title("Generatore di Mappe Mentali")
|
41 |
-
st.write("Carica un PDF o inserisci del testo per generare una mappa mentale.")
|
42 |
-
|
43 |
-
# Input options
|
44 |
-
input_option = st.radio("Scegli un'opzione:", ('Carica PDF', 'Scrivi Testo'))
|
45 |
-
if input_option == 'Carica PDF':
|
46 |
-
uploaded_file = st.file_uploader("Scegli un file PDF...", type="pdf")
|
47 |
-
if uploaded_file is not None:
|
48 |
-
text = extract_text_from_pdf(uploaded_file)
|
49 |
-
st.text_area("Testo estratto:", text, height=300)
|
50 |
-
else:
|
51 |
-
text = st.text_area("Inserisci il testo:", height=300)
|
52 |
-
|
53 |
-
# Dropdown for map options
|
54 |
-
map_type = st.selectbox("Scegli il tipo di mappa", ["Mappa Concettuale", "Timeline", "Diagramma di Flusso", "Diagramma a Ragnatela"])
|
55 |
-
|
56 |
-
# Button to generate the map
|
57 |
-
if st.button("Genera Mappa"):
|
58 |
-
if text:
|
59 |
-
images = search_images(text.split()[:3]) # Use the first three words for the search
|
60 |
-
mind_map = create_mind_map(text.split('\n'), images)
|
61 |
-
st.graphviz_chart(mind_map)
|
62 |
-
else:
|
63 |
-
st.warning("Per favore, inserisci del testo o carica un PDF.")
|
64 |
-
|
65 |
-
st.write("Prova a scrivere del testo breve o a caricare un PDF per vedere come funziona.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|