kawaa99 commited on
Commit
76b7e39
·
verified ·
1 Parent(s): ecc2a2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -3,7 +3,7 @@ import uuid
3
 
4
  from utils import (
5
  load_idioms, generate_audio, init_db, add_favorite, get_favorite,
6
- detect_idioms, translate_literal, normalize_idiom, build_examples_map, remove_favorite,
7
  generate_adaptive_quiz, update_analytics, get_learning_stats, detect_idioms_ai
8
  )
9
 
@@ -99,10 +99,11 @@ elif mode == "Idioms in sentences":
99
  text = st.text_area("Write your text:")
100
 
101
  if st.button("Detect"):
102
- found = detect_idioms(text, idioms)
103
  # use AI if no matching idioms
104
  if not found:
105
  found = detect_idioms_ai(text, idiom_map)
 
106
 
107
  if not found:
108
  st.info("No idioms detected.")
@@ -111,8 +112,9 @@ elif mode == "Idioms in sentences":
111
  # Highlight detected idioms in the text
112
  highlighted_text = text
113
  for idiom in found:
 
114
  highlighted_text = highlighted_text.replace(
115
- idiom,
116
  f"<span style='background-color: #FFAB91; font-weight:bold'>{idiom}</span>"
117
  )
118
  st.markdown("### Your Text with Detected Idioms")
 
3
 
4
  from utils import (
5
  load_idioms, generate_audio, init_db, add_favorite, get_favorite,
6
+ detect_idioms, lemmatize_word, translate_literal, normalize_idiom, build_examples_map, remove_favorite,
7
  generate_adaptive_quiz, update_analytics, get_learning_stats, detect_idioms_ai
8
  )
9
 
 
99
  text = st.text_area("Write your text:")
100
 
101
  if st.button("Detect"):
102
+ found, spans = detect_idioms(text, idioms) #add spans
103
  # use AI if no matching idioms
104
  if not found:
105
  found = detect_idioms_ai(text, idiom_map)
106
+ spans = {idiom: idiom for idiom in found}
107
 
108
  if not found:
109
  st.info("No idioms detected.")
 
112
  # Highlight detected idioms in the text
113
  highlighted_text = text
114
  for idiom in found:
115
+ matched_text = spans.get(idiom, idiom) #instead idiom
116
  highlighted_text = highlighted_text.replace(
117
+ matched_text,
118
  f"<span style='background-color: #FFAB91; font-weight:bold'>{idiom}</span>"
119
  )
120
  st.markdown("### Your Text with Detected Idioms")