Abdul-Rheman's picture
Update app.py
4ebbf5e verified
raw
history blame
3.26 kB
import os
os.environ["GROQ_API_KEY"] = "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"
import streamlit as st
import os
from groq import Groq
# Set up Groq API
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# 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 *'The impact of technology on education.'*")
# 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
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)
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
st.experimental_rerun()