File size: 4,418 Bytes
573d6e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

# Define images and corresponding titles and original sentences
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."
    },
    {
        "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."
    },
    {
        "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."
    },
    {
        "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."
    },
    {
        "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."
    },
    {
        "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."
    },
    {
        "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."
    },
    {
        "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."
    }
]

# Function to collect student's sentences
def collect_sentences(*sentences):
    return list(sentences)

# Function to compare student's sentences with original sentences
def compare_sentences(sentences):
    comparisons = []
    for i, item in enumerate(images_and_titles):
        comparisons.append(f"**{item['title']}**\n\n**Your Sentence:** {sentences[i]}\n\n**Original Sentence:** {item['sentence']}\n\n")
    return "\n".join(comparisons)

# 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)
            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):
        collected_sentences = collect_sentences(*sentences)
        comparison = compare_sentences(collected_sentences)
        final_story = show_final_story(collected_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()