kawaa99 commited on
Commit
162f3dd
·
verified ·
1 Parent(s): c93339e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -3
app.py CHANGED
@@ -53,19 +53,52 @@ if mode == "Explore Idioms":
53
  add_favorite(conn, selected)
54
  st.success("Added to favorites!")
55
 
 
56
  # DETECT
57
 
58
  elif mode == "Idioms in sentences":
59
  text = st.text_area("Write your text:")
 
60
  if st.button("Detect"):
61
  found = detect_idioms(text, idioms)
 
62
  if not found:
63
  st.info("No idioms detected.")
64
  else:
 
 
 
 
 
 
 
 
 
 
 
 
65
  for idiom in found:
66
- st.markdown(f"### 🔹 {idiom}")
67
- st.write("Meaning:", idiom_map[idiom])
68
- st.write("Literal:", translate_literal(idiom))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  # QUIZ
71
 
 
53
  add_favorite(conn, selected)
54
  st.success("Added to favorites!")
55
 
56
+
57
  # DETECT
58
 
59
  elif mode == "Idioms in sentences":
60
  text = st.text_area("Write your text:")
61
+
62
  if st.button("Detect"):
63
  found = detect_idioms(text, idioms)
64
+
65
  if not found:
66
  st.info("No idioms detected.")
67
  else:
68
+ # Highlight detected idioms in the text
69
+ highlighted_text = text
70
+ for idiom in found:
71
+ highlighted_text = highlighted_text.replace(
72
+ idiom,
73
+ f"<span style='background-color: #ffff00; font-weight:bold'>{idiom}</span>"
74
+ )
75
+ st.markdown("### Your Text with Detected Idioms")
76
+ st.markdown(highlighted_text, unsafe_allow_html=True)
77
+ st.markdown("---")
78
+
79
+ # Show idiom details
80
  for idiom in found:
81
+ with st.expander(f"🔹 {idiom}"):
82
+ st.write("**Meaning:**", idiom_map[idiom])
83
+ st.write("**Literal Translation:**", translate_literal(idiom))
84
+
85
+ # Examples
86
+ examples = examples_map.get(idiom.lower(), [])
87
+ if examples:
88
+ st.subheader("Examples:")
89
+ for ex in examples[:2]:
90
+ st.write("•", ex["en"])
91
+ else:
92
+ st.write("No examples available.")
93
+
94
+ # Audio
95
+ audio_file = generate_audio(idiom)
96
+ st.audio(audio_file)
97
+
98
+ # Practice button
99
+ if st.button(f"Practice '{idiom}'"):
100
+ st.session_state.quiz = generate_ai_question_dynamic([idiom])
101
+ st.rerun()
102
 
103
  # QUIZ
104