Spaces:
Sleeping
Sleeping
File size: 10,854 Bytes
e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 e1ed697 f277860 34b9661 f277860 34b9661 f277860 e1ed697 f277860 e1ed697 f277860 34b9661 f277860 34b9661 f277860 34b9661 f277860 e1ed697 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
import gradio as gr
import re
# Define images and corresponding titles, original sentences, and examples
images_and_titles = [
{
"title": "1. Echo Ridge Village",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Echo%20Ridge%20Village.png?raw=true",
"sentence": "In the small mountain village of Echo Ridge, adventure was a part of everyday life.",
"example": "small mountain village / Echo Ridge / adventure / part of everyday life (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "2. Alex finding the map",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Alex%20Finding%20the%20map.png?raw=true",
"sentence": "One day, while exploring the local library, Alex stumbled upon an ancient map tucked inside a forgotten book on village lore.",
"example": "explore the local library / One day / tuck inside a forgotten book / Alex stumble upon an ancient map (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "3. Alex, Mia, and Sam preparing for the expedition",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Preparing%20for%20the%20expedition.png?raw=true",
"sentence": "Knowing the journey would be risky, he enlisted the help of his best friends, Mia and Sam.",
"example": "the help / Know the journey would be risky / enlist / Mia and Sam / of his best friends (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "4. The journey begins at dawn",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Journey%20begins%20at%20dawn.png?raw=true",
"sentence": "Their journey began at dawn. They trekked through dense forests, crossed rushing streams, and climbed steep cliffs.",
"example": "trek through dense forests / Their journey begin at dawn / cross rushing streams / climb steep cliffs (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "5. Reaching Whispering Hollow",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Reaching%20whispering%20hollow.png?raw=true",
"sentence": "After hours of hiking, they finally reached Whispering Hollow.",
"example": "reach / After hours of hiking / they finally / Whispering Hollow (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "6. Exploring the cave",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Exploring%20the%20cave.png?raw=true",
"sentence": "Using their flashlights, they ventured deeper into the cave, guided by the markings on the map.",
"example": "they venture deeper into the cave / Using their flashlights / guide by the markings / on the map (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "7. Finding the ancient chest",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Finding%20the%20ancient%20chest.png?raw=true",
"sentence": "As they reached the heart of the cave, they discovered an ancient chest hidden behind a fallen boulder.",
"example": "discover an ancient chest / hidden behind / As they reach the heart of the cave / a fallen boulder (λμ¬ νν λ³ν κ°λ₯)"
},
{
"title": "8. Village celebration",
"image": "https://github.com/englissi/englissi/blob/00d4ac2ab7d8b88169af3afe332897db02056a28/Sample/wordcloud_Village%20celebration.png?raw=true",
"sentence": "The village celebrated their discovery, and the children were hailed as heroes.",
"example": "The village celebrate their discovery / the children / be hail / as heroes (λμ¬ νν λ³ν κ°λ₯)"
}
]
# Helper function to provide corrective feedback for verb errors
def provide_feedback(word, correct_word, form_type):
if form_type == "participle":
return f"λΆμ¬κ΅¬λ¬Έ '{word}'μ μ£Όμ μ μ£Όμ΄μ λΆμμ μ μ£Όμ΄κ° κ°μ κ²½μ°μ μ¬μ©λ©λλ€."
elif form_type == "past_simple":
return f"λμ¬ '{word}'μ κ³Όκ±°νμ '{correct_word}'μ
λλ€."
elif form_type == "modal_auxiliary":
return f"μ‘°λμ¬ '{word}'λ νμ λμ¬ μνκ³Ό ν¨κ» μ¬μ©λ©λλ€."
elif form_type == "past_participle":
return f"λμ¬ '{word}'μ κ³Όκ±°λΆμ¬λ '{correct_word}'μ
λλ€."
else:
return f"λμ¬ '{word}'μ ννκ° μ¬λ°λ₯΄μ§ μμ΅λλ€."
# Function to find the correct past tense of a verb
def get_correct_past_tense(word, sentence, original_sentence):
word = word.lower()
words = original_sentence.lower().split()
for i, w in enumerate(words):
if w.lower() == word:
return words[i]
return None
# Function to compare student's sentences with original sentences and provide feedback
def compare_sentences(sentences):
comparisons = []
error_counts = {
"Past Simple": 0,
"Present Participle": 0,
"Past Participle": 0,
"Modal Auxiliary": 0
}
verb_forms_info = {
"In the small mountain village of Echo Ridge, adventure was a part of everyday life.": [
"Verb Form: Past Simple ('was')"
],
"One day, while exploring the local library, Alex stumbled upon an ancient map tucked inside a forgotten book on village lore.": [
"Verb Form: Past Simple ('stumbled')",
"Participle Construction: Present Participle ('exploring')",
"Participle Construction: Past Participle ('tucked', 'forgotten')"
],
"Knowing the journey would be risky, he enlisted the help of his best friends, Mia and Sam.": [
"Verb Form: Past Simple ('enlisted')",
"Participle Construction: Present Participle ('Knowing')",
"Auxiliary Verb: Modal ('would be')"
],
"Their journey began at dawn. They trekked through dense forests, crossed rushing streams, and climbed steep cliffs.": [
"Verb Form: Past Simple ('began', 'trekked', 'crossed', 'climbed')"
],
"After hours of hiking, they finally reached Whispering Hollow.": [
"Verb Form: Past Simple ('reached')",
"Participle Construction: Present Participle ('hiking')"
],
"Using their flashlights, they ventured deeper into the cave, guided by the markings on the map.": [
"Verb Form: Past Simple ('ventured')",
"Participle Construction: Present Participle ('Using')",
"Participle Construction: Past Participle ('guided')"
],
"As they reached the heart of the cave, they discovered an ancient chest hidden behind a fallen boulder.": [
"Verb Form: Past Simple ('reached', 'discovered')",
"Participle Construction: Past Participle ('hidden', 'fallen')"
],
"The village celebrated their discovery, and the children were hailed as heroes.": [
"Verb Form: Past Simple ('celebrated')",
"Verb Form: Past Simple Passive ('were hailed')"
]
}
for i, item in enumerate(images_and_titles):
feedback = ""
student_sentence = sentences[i].strip()
original_sentence = item["sentence"].strip()
student_words = re.findall(r'\b\w+\b', student_sentence)
original_words = re.findall(r'\b\w+\b', original_sentence)
# Initial feedback header
feedback += f"**Your Sentence:** {student_sentence}\n\n**Original Sentence:** {original_sentence}\n\n"
# Verb forms in the original sentence
feedback += "Verb Forms in the Original Sentence:\n"
for verb_info in verb_forms_info[original_sentence]:
feedback += f"- {verb_info}\n"
feedback += "\n"
# Check for verb errors
for word in student_words:
if word.lower() not in [w.lower() for w in original_words]:
correct_word = get_correct_past_tense(word, student_sentence, original_sentence)
if correct_word:
feedback += provide_feedback(word, correct_word, "past_simple") + "\n"
error_counts["Past Simple"] += 1
# Check for participle construction errors
participles = ["knowing", "exploring", "tucked", "forgotten", "guided", "hidden", "fallen"]
for participle in participles:
if re.search(rf'\b{participle}\b', student_sentence, re.IGNORECASE):
feedback += provide_feedback(participle, "", "participle") + "\n"
if participle in ["exploring", "Knowing", "hiking", "Using"]:
error_counts["Present Participle"] += 1
else:
error_counts["Past Participle"] += 1
# Check for modal auxiliary verb errors
if re.search(r'\bwould be\b', student_sentence, re.IGNORECASE) and 'would be' not in original_sentence.lower():
feedback += provide_feedback("would be", "would be", "modal_auxiliary") + "\n"
error_counts["Modal Auxiliary"] += 1
comparisons.append(f"**{item['title']}**\n\n{feedback}\n")
error_summary = (
f"Past Simple Errors: {error_counts['Past Simple']}\n"
f"Present Participle Errors: {error_counts['Present Participle']}\n"
f"Past Participle Errors: {error_counts['Past Participle']}\n"
f"Modal Auxiliary Errors: {error_counts['Modal Auxiliary']}\n"
)
return "\n".join(comparisons) + "\n" + error_summary
# Function to show the student's final story
def show_final_story(sentences):
return "\n".join(sentences)
# Create the Gradio interface
with gr.Blocks() as iface:
gr.Markdown("# The Guardian's Secret: Rewriting Exercise")
sentence_inputs = []
for item in images_and_titles:
with gr.Row():
gr.Markdown(f"### {item['title']}")
gr.Image(value=item['image'], interactive=False)
gr.Markdown(f"**Example:** {item['example']}")
sentence_input = gr.Textbox(label="Your Sentence", interactive=True)
sentence_inputs.append(sentence_input)
finish_button = gr.Button("Finish")
comparison_output = gr.Markdown(visible=False)
final_story_output = gr.Markdown(visible=False)
def on_finish(*sentences):
comparison = compare_sentences(sentences)
final_story = show_final_story(sentences)
return gr.update(visible=True, value=comparison), gr.update(visible=True, value=final_story)
finish_button.click(fn=on_finish, inputs=sentence_inputs, outputs=[comparison_output, final_story_output])
iface.launch()
|