MANIKANDAN A
commited on
Commit
·
4fb58bf
1
Parent(s):
db4c5e7
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,6 @@ import numpy as np
|
|
9 |
import streamlit as st
|
10 |
import requests
|
11 |
import nltk
|
12 |
-
import string
|
13 |
-
from collections import Counter
|
14 |
from PIL import Image
|
15 |
from poetpy import get_poetry
|
16 |
from nltk.corpus import stopwords
|
@@ -349,15 +347,13 @@ caption_model = get_model()
|
|
349 |
|
350 |
@st.cache_data
|
351 |
def extract_important_term(caption):
|
352 |
-
# Remove stopwords
|
353 |
stop_words = set(stopwords.words('english'))
|
354 |
words = caption.lower().split()
|
355 |
-
|
356 |
-
|
357 |
-
# Count word frequencies
|
358 |
-
word_freq = Counter(words)
|
359 |
-
important_term = max(word_freq, key=word_freq.get)
|
360 |
|
|
|
|
|
361 |
|
362 |
return important_term
|
363 |
|
@@ -386,7 +382,7 @@ def predict(term_col, poem_col):
|
|
386 |
important_term = extract_important_term(pred_caption)
|
387 |
|
388 |
# Generate poem using poetpy
|
389 |
-
poem_lines = generate_poem(
|
390 |
|
391 |
# Display the poem
|
392 |
|
|
|
9 |
import streamlit as st
|
10 |
import requests
|
11 |
import nltk
|
|
|
|
|
12 |
from PIL import Image
|
13 |
from poetpy import get_poetry
|
14 |
from nltk.corpus import stopwords
|
|
|
347 |
|
348 |
@st.cache_data
|
349 |
def extract_important_term(caption):
|
350 |
+
# Remove stopwords
|
351 |
stop_words = set(stopwords.words('english'))
|
352 |
words = caption.lower().split()
|
353 |
+
filtered_words = [word for word in words if word not in stop_words]
|
|
|
|
|
|
|
|
|
354 |
|
355 |
+
# Find the longest word
|
356 |
+
important_term = max(filtered_words, key=len)
|
357 |
|
358 |
return important_term
|
359 |
|
|
|
382 |
important_term = extract_important_term(pred_caption)
|
383 |
|
384 |
# Generate poem using poetpy
|
385 |
+
poem_lines = generate_poem(important_term, num_lines=10)
|
386 |
|
387 |
# Display the poem
|
388 |
|