Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,21 +26,17 @@ pdf_file = st.file_uploader("Upload PDF", type=["pdf"])
|
|
| 26 |
if pdf_file is not None:
|
| 27 |
st.write("Processing the PDF...")
|
| 28 |
text = extract_text_from_pdf(pdf_file)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
for genre, score in top_genres:
|
| 43 |
-
st.write(f"**{genre.capitalize()}**: {score:.2f}")
|
| 44 |
-
else:
|
| 45 |
-
st.error("No text could be extracted from the PDF. Please try another file.")
|
| 46 |
|
|
|
|
| 26 |
if pdf_file is not None:
|
| 27 |
st.write("Processing the PDF...")
|
| 28 |
text = extract_text_from_pdf(pdf_file)
|
| 29 |
+
if text.strip():
|
| 30 |
+
st.write("PDF Text Extracted. Performing Genre Classification...")
|
| 31 |
+
classifier = pipeline("zero-shot-classification", model = "facebook/bart-large-mnli") #load_classifier()
|
| 32 |
+
# Define candidate genres
|
| 33 |
+
candidate_labels =["Romance", "Mystery", "Thriller", "Science Fiction", "Fantasy", "Horror", "Historical Fiction", "Crime", "Western", "Dystopian", "Biography", "Autobiography", "Memoir", "History", "Self-Help", "Travel", "Essay", "Journalism", "Sonnet", "Haiku", "Free Verse", "Narrative Poetry", "Lyric Poetry", "Tragedy", "Comedy", "Melodrama", "Farce", "Graphic Novel", "Epistolary", "Magical Realism", "Satire", "Young Adult Fiction"]
|
| 34 |
+
# Perform zero-shot classification
|
| 35 |
+
result = classifier(text),#[:1000], candidate_labels, multi_label=True) # Using the first 1000 characters
|
| 36 |
+
genres = sorted(zip(result["labels"], result["scores"]), key=lambda x: x[1], reverse=Truest.subheader("Top 20 Detected Genres:")
|
| 37 |
+
top_genres = genres[:20]
|
| 38 |
+
for genre, score in top_genres:
|
| 39 |
+
st.write(f"**{genre.capitalize()}**: {score:.2f}")
|
| 40 |
+
else:
|
| 41 |
+
st.error("No text could be extracted from the PDF. Please try another file.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|