Fluospark128 commited on
Commit
fdb40a4
·
verified ·
1 Parent(s): 5bd8bbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
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
- if text.strip():
31
- st.write("PDF Text Extracted. Performing Genre Classification...")
32
- classifier = pipeline("zero-shot-classification", model = "facebook/bart-large-mnli") #load_classifier()
33
-
34
- # Define candidate genres
35
- 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"]
36
- # Perform zero-shot classification
37
- result = classifier(text),#[:1000], candidate_labels, multi_label=True)  # Using the first 1000 characters
38
- genres = sorted(zip(result["labels"], result["scores"]), key=lambda x: x[1], reverse=True)
39
-
40
- st.subheader("Top 20 Detected Genres:")
41
- top_genres = genres[:20]
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