MANIKANDAN A commited on
Commit
db4c5e7
1 Parent(s): d50f4f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -9,6 +9,8 @@ import numpy as np
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,13 +349,15 @@ 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
- filtered_words = [word for word in filtered_words if re.match(r'^[a-zA-Z]+$', word)]
355
- # Find the longest word
356
- important_term = filtered_words
 
 
357
 
358
  return important_term
359
 
 
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
 
350
  @st.cache_data
351
  def extract_important_term(caption):
352
+ # Remove stopwords and punctuation
353
  stop_words = set(stopwords.words('english'))
354
  words = caption.lower().split()
355
+ words = [word.strip(string.punctuation) for word in words if word not in stop_words]
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