Spaces:
Running
Running
Flavio
commited on
Commit
·
12b57fb
1
Parent(s):
5998493
Primo esempio di summarization
Browse files
HFBot.py
CHANGED
|
@@ -46,6 +46,12 @@ class HFBot():
|
|
| 46 |
#print(prompt)
|
| 47 |
rersponse = self.genera(prompt)
|
| 48 |
return rersponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def genera(self, prompt: str):
|
| 50 |
retval = ""
|
| 51 |
messages = [
|
|
|
|
| 46 |
#print(prompt)
|
| 47 |
rersponse = self.genera(prompt)
|
| 48 |
return rersponse
|
| 49 |
+
|
| 50 |
+
def riassumi(self, text):
|
| 51 |
+
retval =""
|
| 52 |
+
pipe = pipeline("summarization", model=self.model_name)
|
| 53 |
+
retval = pipe(text)
|
| 54 |
+
return retval
|
| 55 |
def genera(self, prompt: str):
|
| 56 |
retval = ""
|
| 57 |
messages = [
|
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from HFBot import HFBot
|
| 4 |
-
|
| 5 |
-
|
| 6 |
def main():
|
| 7 |
modelliLLM = [
|
| 8 |
'Almawave/Velvet-2B',
|
|
@@ -11,6 +11,12 @@ def main():
|
|
| 11 |
'sapienzanlp/Minerva-350M-base-v1.0',
|
| 12 |
'Qwen/Qwen3-0.6B'
|
| 13 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
modello_scelto = st.selectbox("Seleziona un modello:", modelliLLM, index=0)
|
| 15 |
st.write(f"Hai selezionato: {modello_scelto}")
|
| 16 |
|
|
@@ -23,18 +29,41 @@ def main():
|
|
| 23 |
|
| 24 |
#res = LLM.chat(domanda=domanda, istruzioni= Istruzioni, frammenti=frammenti)
|
| 25 |
#st.write(f"Domanda {domanda} - risposta {res}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
if "atto_caricato" not in st.session_state:
|
| 30 |
st.subheader("Carica l'atto principale (Determinazione)")
|
| 31 |
|
| 32 |
main_pdf = st.file_uploader("Carica 1 file PDF - Determinazione", type=["pdf"], key="main_pdf")
|
| 33 |
if main_pdf:
|
| 34 |
-
st.session_state
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
from transformers import pipeline
|
| 4 |
from HFBot import HFBot
|
| 5 |
+
from textutils import ParagraphDocumentProcessor, WholeTextDocumentProcessor, SmallFragmentDocumentProcessor
|
|
|
|
| 6 |
def main():
|
| 7 |
modelliLLM = [
|
| 8 |
'Almawave/Velvet-2B',
|
|
|
|
| 11 |
'sapienzanlp/Minerva-350M-base-v1.0',
|
| 12 |
'Qwen/Qwen3-0.6B'
|
| 13 |
]
|
| 14 |
+
|
| 15 |
+
UPLOAD_DIR="/tmp/"
|
| 16 |
+
if "indice_creato" not in st.session_state:
|
| 17 |
+
st.session_state["indice_creato"] = False
|
| 18 |
+
|
| 19 |
+
testi = []
|
| 20 |
modello_scelto = st.selectbox("Seleziona un modello:", modelliLLM, index=0)
|
| 21 |
st.write(f"Hai selezionato: {modello_scelto}")
|
| 22 |
|
|
|
|
| 29 |
|
| 30 |
#res = LLM.chat(domanda=domanda, istruzioni= Istruzioni, frammenti=frammenti)
|
| 31 |
#st.write(f"Domanda {domanda} - risposta {res}")
|
| 32 |
+
st.title("Suddivisione in paragrafi")
|
| 33 |
+
docprocessor_options = {
|
| 34 |
+
"ParagraphDocumentProcessor": ParagraphDocumentProcessor(),
|
| 35 |
+
"WholeText": WholeTextDocumentProcessor(),
|
| 36 |
+
"Small Fragments": SmallFragmentDocumentProcessor(),
|
| 37 |
+
}
|
| 38 |
+
selected_docprocessor = st.selectbox("Divisione in paragrafi", docprocessor_options.keys())
|
| 39 |
+
docprocessor = docprocessor_options[selected_docprocessor]
|
| 40 |
+
st.write(f"Hai selezionato: **{selected_docprocessor}**")
|
| 41 |
|
| 42 |
+
if not st.session_state["indice_creato"]:
|
|
|
|
|
|
|
| 43 |
st.subheader("Carica l'atto principale (Determinazione)")
|
| 44 |
|
| 45 |
main_pdf = st.file_uploader("Carica 1 file PDF - Determinazione", type=["pdf"], key="main_pdf")
|
| 46 |
if main_pdf:
|
| 47 |
+
st.session_state["main_pdf_nome"] = main_pdf.name
|
| 48 |
+
if st.button("Esegui analisi"):
|
| 49 |
+
if main_pdf is not None:
|
| 50 |
+
try:
|
| 51 |
+
save_path = os.path.join(UPLOAD_DIR, main_pdf.name)
|
| 52 |
+
with open(save_path, "wb") as f:
|
| 53 |
+
f.write(main_pdf.read())
|
| 54 |
+
st.success(f"✅ Determinazione caricata con successo! File salvato in: `{save_path}`")
|
| 55 |
+
testi= docprocessor.estrai_da_pdf(save_path)
|
| 56 |
+
st.write(testi[:50])
|
| 57 |
+
#ßragpipeline.aggiungi_file_pdf(save_path)
|
| 58 |
+
st.session_state["indice_creato"] = True
|
| 59 |
+
except Exception as e:
|
| 60 |
+
st.error(f"❌ Errore nel salvataggio del file: {e}")
|
| 61 |
+
else:
|
| 62 |
+
st.warning("Nessun PDF di Determinazione caricato.")
|
| 63 |
+
if st.session_state["indice_creato"]:
|
| 64 |
+
st.write("Eseguo riassunto")
|
| 65 |
+
summary = LLM.riassumi(testi)
|
| 66 |
+
st.success(summary)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
main()
|