File size: 4,070 Bytes
ab36abf
 
9b96b2f
 
 
717aee5
 
 
ab36abf
9b96b2f
 
 
 
 
 
 
 
 
 
 
 
 
ab36abf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b96b2f
ab36abf
 
 
9b96b2f
 
ab36abf
 
 
 
 
9b96b2f
ab36abf
9b96b2f
 
ab36abf
 
 
 
 
 
 
 
 
 
 
 
9b96b2f
ab36abf
 
 
 
 
 
 
 
 
 
 
 
 
9b96b2f
 
 
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
import os
from groq import Groq
import streamlit as st

# Set up Groq API client
GROQ_API_KEY="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"

client = Groq(api_key=GROQ_API_KEY)

# Predefined topics
topics = [
    "The impact of technology on education.",
    "The importance of mental health awareness.",
    "How social media affects communication skills.",
    "The benefits of reading for personal growth.",
    "Climate change and its global impact.",
    "The role of artificial intelligence in everyday life.",
    "The significance of physical fitness in modern life.",
    "Why we should promote gender equality in the workplace.",
    "The effects of globalization on local cultures.",
    "The importance of renewable energy sources."
]

# App Title
st.title("πŸ“˜ Writing Assistant for IELTS/DET/TOEFL")
st.subheader("Improve your English Writing Skills with AI-powered Feedback")

# Plans Section
st.markdown("### Choose Your Plan:")
col1, col2, col3 = st.columns(3)

with col1:
    st.subheader("30 Days Plan")
    st.write("Focus on key areas of improvement daily.")
    if st.button("Select 30 Days Plan"):
        st.session_state.plan = "30 Days"

with col2:
    st.subheader("45 Days Plan")
    st.write("Build advanced writing skills over time.")
    if st.button("Select 45 Days Plan"):
        st.session_state.plan = "45 Days"

with col3:
    st.subheader("60 Days Plan")
    st.write("Achieve mastery with detailed feedback.")
    if st.button("Select 60 Days Plan"):
        st.session_state.plan = "60 Days"

# Display selected plan and current day
if "plan" in st.session_state:
    st.markdown(f"### Selected Plan: **{st.session_state.plan}**")
    if "current_day" not in st.session_state:
        st.session_state.current_day = 1
    st.markdown(f"**Day {st.session_state.current_day}** Topic: Write an essay on *'{topics[st.session_state.current_day - 1]}'*")

# Essay Submission Section
st.markdown("### Submit Your Essay")
user_input = st.text_area("Write your essay here (minimum 150 words):", height=300)

if st.button("Submit for Feedback"):
    if len(user_input.split()) < 150:
        st.error("Please write at least 150 words before submitting.")
    else:
        with st.spinner("Processing your essay..."):
            # Send the essay to Groq API for feedback
            prompt = f"""
            You are an expert academic writer with 40 years of experience in providing concise but effective feedback. 
            Instead of asking the student to do this and that, you just say replace this with this to improve concisely.
            Analyze the following essay: {user_input}.
            {st.session_state.plan} level user should get feedback specific to their level.
            """
            chat_completion = client.chat.completions.create(
                messages=[{"role": "user", "content": prompt}],
                model="llama3-8b-8192",
            )
            feedback = chat_completion.choices[0].message.content
            st.success("Feedback Generated!")
            st.markdown("### Feedback")
            st.write(feedback)

            # Provide improved version of the essay
            st.markdown("### Improved Version")
            st.write("Here's how your essay could look with the suggested improvements:")
            improved_prompt = f"Revise the following essay for {st.session_state.plan} level user: {user_input}"
            improved_completion = client.chat.completions.create(
                messages=[{"role": "user", "content": improved_prompt}],
                model="llama3-8b-8192",
            )
            improved_essay = improved_completion.choices[0].message.content
            st.write(improved_essay)

# Navigation for Next Day
if "plan" in st.session_state and st.button("Next Day"):
    st.session_state.current_day += 1
    if st.session_state.current_day > len(topics):  # Reset to day 1 if all days are completed
        st.session_state.current_day = 1
    st.rerun()  # Use st.experimental_rerun() to re-run the app and update the day and topic