File size: 6,185 Bytes
8d5d73e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ctransformers import AutoModelForCausalLM

# Load model
MODEL_NAME = "TheBloke/OpenHermes-2.5-Mistral-7B-GGUF"
MODEL_FILE = "openhermes-2.5-mistral-7b.Q4_K_M.gguf"
MODEL_TYPE = "mistral"

print("Loading model...")
model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME,
    model_file=MODEL_FILE,
    model_type=MODEL_TYPE,
    gpu_layers=0,
    context_length=2048,
    max_new_tokens=1024,
    temperature=0.7,
    top_p=0.95,
    top_k=40,
    repetition_penalty=1.1
)
print("Model loaded successfully!")

# Define the evaluation function
def evaluate(topic, essay):
    # Create the prompt with the provided template
    prompt = f"""### Instruction:
You are an IELTS writing examiner. Please evaluate the following essay based on IELTS Task 2 criteria: Task Achievement, Coherence and Cohesion, Lexical Resource, and Grammatical Range and Accuracy. Provide detailed feedback for each criterion, including a band score (from 1.0 to 9.0, in increments of 0.5, e.g., 6.5). Calculate an overall band score as the average of the four criteria, rounded to the nearest 0.5. Include a Feedback section with three sub-sections: Strengths, Areas for Improvement, and Strategies for Enhancement, each containing at least one bullet point.

### Input:
Essay Prompt:
{topic}

Essay:
{essay}

### Response:
**Task Achievement:**
    - [Provide detailed feedback on how well the essay addresses the task, supports arguments, and meets the requirements.]
    - Suggested Band Score: [X.X]

    **Coherence and Cohesion:**
    - [Provide detailed feedback on the essay's structure, logical flow, and use of cohesive devices.]
    - Suggested Band Score: [X.X]

    **Lexical Resource:**
    - [Provide detailed feedback on the range, accuracy, and appropriateness of vocabulary.]
    - Suggested Band Score: [X.X]

    **Grammatical Range and Accuracy:**
    - [Provide detailed feedback on the variety, complexity, and accuracy of grammatical structures.]
    - Suggested Band Score: [X.X]

    **Overall Band Score:**
    - [Summarizing the essay’s overall performance, including what the writer does well and what needs the most improvement]
    - Suggested Overall Band Score: [X.X]

    **Feedback:**
    **Strengths:**
    - [List at least one strength of the essay.]

    **Areas for Improvement:**
    - [List at least one area where the essay can be improved.]

    **Strategies for Enhancement:**
    - [List at least one specific strategy to help the writer improve.]
"""
    
    # Generate the response directly using the model
    # The ctransformers model has a __call__ method that accepts a string
    # and returns the generated text
    response = model(prompt)
    
    # Clean the response if needed
    if "<|im_end|>" in response:
        response = response.split("<|im_end|>")[0]
    
    return response.strip()

# Build Gradio Interface
iface = gr.Interface(
    fn=evaluate,
    inputs=[
        gr.Textbox(label="Essay Topic", lines=2, placeholder="Enter essay topic..."),
        gr.Textbox(label="Essay", lines=12, placeholder="Paste your essay here...")
    ],
    outputs=gr.Textbox(label="Evaluation Result"),
    title="IELTS Writing Evaluator",
    description="Input your Task 2 essay to get full IELTS evaluation.",
    examples=[
        [
            "Some people think that technology is making our lives more complicated. To what extent do you agree or disagree?",
            "In today's rapidly evolving digital landscape, technology has become an integral part of our daily lives. While some argue that technological advancements have made life more complex and challenging to navigate, I largely disagree with this perspective. I believe that when properly utilized, technology streamlines processes, enhances connectivity, and ultimately simplifies various aspects of human existence.\n\nFirstly, technology has revolutionized how we handle routine tasks. Mobile applications and digital platforms have simplified activities ranging from banking and shopping to accessing government services. Instead of standing in long queues or navigating bureaucratic procedures, individuals can now complete these tasks with a few taps on their smartphones. For instance, mobile banking apps allow users to transfer money instantly rather than visiting physical bank branches during limited operating hours. This clearly demonstrates how technology simplifies rather than complicates our daily routines.\n\nSecondly, technology has transformed communication and information access. Through social media platforms, video conferencing tools, and instant messaging applications, people can now connect with others around the globe effortlessly. Distance is no longer a barrier to maintaining relationships or collaborating professionally. Furthermore, the internet has democratized information access, allowing individuals to learn new skills, research topics of interest, and stay informed about global events. This unprecedented access to knowledge and connectivity has simplified how we interact with the world rather than adding complexity.\n\nNevertheless, I acknowledge that technological advancement presents certain challenges. The rapid pace of change often requires individuals to continuously learn new skills and adapt to emerging platforms. Additionally, issues such as digital privacy concerns, information overload, and technological dependence are valid considerations. However, these challenges represent growing pains rather than evidence that technology inherently complicates life.\n\nIn conclusion, while technology adoption involves a learning curve and presents some challenges, I firmly believe that it ultimately simplifies rather than complicates human existence. The convenience, efficiency, and connectivity that technology provides far outweigh the temporary complexities associated with adapting to new systems. As we continue to develop more intuitive interfaces and inclusive technological solutions, the simplifying potential of technology will become even more apparent."
        ]
    ]
)

# Launch the interface
if __name__ == "__main__":
    iface.launch(server_name="0.0.0.0", server_port=7860)