Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,8 @@ if pdf_file is not None:
|
|
| 37 |
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"]
|
| 38 |
# Perform zero-shot classification
|
| 39 |
result = classifier(text[:1000], candidate_labels, multi_label=True) #[:1000]), candidate_labels, multi_label=True)
|
| 40 |
-
genres = sorted(zip(result["labels"], result["scores"]), key=lambda x: x[1], reverse=
|
|
|
|
| 41 |
top_genres = genres[:20]
|
| 42 |
for genre, score in top_genres:
|
| 43 |
st.write(f"**{genre.capitalize()}**: {score:.2f}")
|
|
|
|
| 37 |
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"]
|
| 38 |
# Perform zero-shot classification
|
| 39 |
result = classifier(text[:1000], candidate_labels, multi_label=True) #[:1000]), candidate_labels, multi_label=True)
|
| 40 |
+
genres = sorted(zip(result["labels"], result["scores"]), key=lambda x: x[1], reverse=True)
|
| 41 |
+
st.subheader("Top 20 Detected Genres:")
|
| 42 |
top_genres = genres[:20]
|
| 43 |
for genre, score in top_genres:
|
| 44 |
st.write(f"**{genre.capitalize()}**: {score:.2f}")
|