MANIKANDAN A
commited on
Commit
·
67b4e82
1
Parent(s):
443cdfd
Update app.py
Browse files
app.py
CHANGED
@@ -345,6 +345,17 @@ def get_model():
|
|
345 |
|
346 |
caption_model = get_model()
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
|
350 |
def generate_poem(word, num_lines):
|
@@ -367,11 +378,14 @@ def generate_poem(word, num_lines):
|
|
367 |
|
368 |
def predict(term_col, poem_col):
|
369 |
pred_caption = generate_caption('tmp.jpg', caption_model)
|
|
|
|
|
370 |
|
371 |
# Generate poem using poetpy
|
372 |
-
poem_lines = generate_poem(
|
373 |
|
374 |
# Display the poem
|
|
|
375 |
poem_col.markdown('#### Generated Poem:')
|
376 |
poem_col.markdown('<div class="poem-container">', unsafe_allow_html=True)
|
377 |
for line in poem_lines:
|
@@ -379,7 +393,6 @@ def predict(term_col, poem_col):
|
|
379 |
poem_col.markdown('</div>', unsafe_allow_html=True)
|
380 |
|
381 |
|
382 |
-
|
383 |
|
384 |
st.markdown('<h1 style="text-align:center; font-family:Comic Sans MS; width:fit-content; font-size:3em; color:green; text-shadow: 2px 2px 4px #000000;">AUTO POEM GENERATOR</h1>', unsafe_allow_html=True)
|
385 |
col1, col2 = st.columns(2)
|
|
|
345 |
|
346 |
caption_model = get_model()
|
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 = filtered_words
|
357 |
+
|
358 |
+
return important_term
|
359 |
|
360 |
|
361 |
def generate_poem(word, num_lines):
|
|
|
378 |
|
379 |
def predict(term_col, poem_col):
|
380 |
pred_caption = generate_caption('tmp.jpg', caption_model)
|
381 |
+
# Extract the important term
|
382 |
+
important_term = extract_important_term(pred_caption)
|
383 |
|
384 |
# Generate poem using poetpy
|
385 |
+
poem_lines = generate_poem(extract_important_term, num_lines=10)
|
386 |
|
387 |
# Display the poem
|
388 |
+
|
389 |
poem_col.markdown('#### Generated Poem:')
|
390 |
poem_col.markdown('<div class="poem-container">', unsafe_allow_html=True)
|
391 |
for line in poem_lines:
|
|
|
393 |
poem_col.markdown('</div>', unsafe_allow_html=True)
|
394 |
|
395 |
|
|
|
396 |
|
397 |
st.markdown('<h1 style="text-align:center; font-family:Comic Sans MS; width:fit-content; font-size:3em; color:green; text-shadow: 2px 2px 4px #000000;">AUTO POEM GENERATOR</h1>', unsafe_allow_html=True)
|
398 |
col1, col2 = st.columns(2)
|