Spaces:
Sleeping
Sleeping
| 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 | |