Abdul-Rheman commited on
Commit
9b96b2f
Β·
verified Β·
1 Parent(s): 4ebbf5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,13 +1,23 @@
1
  import os
2
- os.environ["GROQ_API_KEY"] = "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"
3
-
4
-
5
- import streamlit as st
6
- import os
7
  from groq import Groq
 
 
 
 
8
 
9
- # Set up Groq API
10
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # App Title
13
  st.title("πŸ“˜ Writing Assistant for IELTS/DET/TOEFL")
@@ -40,21 +50,21 @@ if "plan" in st.session_state:
40
  st.markdown(f"### Selected Plan: **{st.session_state.plan}**")
41
  if "current_day" not in st.session_state:
42
  st.session_state.current_day = 1
43
- st.markdown(f"**Day {st.session_state.current_day}** Topic: Write an essay on *'The impact of technology on education.'*")
44
 
45
  # Essay Submission Section
46
  st.markdown("### Submit Your Essay")
47
- user_input = st.text_area(
48
- "Write your essay here (minimum 150 words):", height=300
49
- )
50
  if st.button("Submit for Feedback"):
51
  if len(user_input.split()) < 150:
52
  st.error("Please write at least 150 words before submitting.")
53
  else:
54
  with st.spinner("Processing your essay..."):
55
- # Send the essay to Groq API
56
  prompt = f"""
57
- 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.
 
58
  Analyze the following essay: {user_input}.
59
  {st.session_state.plan} level user should get feedback specific to their level.
60
  """
@@ -67,6 +77,7 @@ if st.button("Submit for Feedback"):
67
  st.markdown("### Feedback")
68
  st.write(feedback)
69
 
 
70
  st.markdown("### Improved Version")
71
  st.write("Here's how your essay could look with the suggested improvements:")
72
  improved_prompt = f"Revise the following essay for {st.session_state.plan} level user: {user_input}"
@@ -80,4 +91,6 @@ if st.button("Submit for Feedback"):
80
  # Navigation for Next Day
81
  if "plan" in st.session_state and st.button("Next Day"):
82
  st.session_state.current_day += 1
83
- st.experimental_rerun()
 
 
 
1
  import os
 
 
 
 
 
2
  from groq import Groq
3
+ import streamlit as st
4
+
5
+ # Set up Groq API client
6
+ client = Groq(api_key=os.environ.get("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"))
7
 
8
+ # Predefined topics
9
+ topics = [
10
+ "The impact of technology on education.",
11
+ "The importance of mental health awareness.",
12
+ "How social media affects communication skills.",
13
+ "The benefits of reading for personal growth.",
14
+ "Climate change and its global impact.",
15
+ "The role of artificial intelligence in everyday life.",
16
+ "The significance of physical fitness in modern life.",
17
+ "Why we should promote gender equality in the workplace.",
18
+ "The effects of globalization on local cultures.",
19
+ "The importance of renewable energy sources."
20
+ ]
21
 
22
  # App Title
23
  st.title("πŸ“˜ Writing Assistant for IELTS/DET/TOEFL")
 
50
  st.markdown(f"### Selected Plan: **{st.session_state.plan}**")
51
  if "current_day" not in st.session_state:
52
  st.session_state.current_day = 1
53
+ st.markdown(f"**Day {st.session_state.current_day}** Topic: Write an essay on *'{topics[st.session_state.current_day - 1]}'*")
54
 
55
  # Essay Submission Section
56
  st.markdown("### Submit Your Essay")
57
+ user_input = st.text_area("Write your essay here (minimum 150 words):", height=300)
58
+
 
59
  if st.button("Submit for Feedback"):
60
  if len(user_input.split()) < 150:
61
  st.error("Please write at least 150 words before submitting.")
62
  else:
63
  with st.spinner("Processing your essay..."):
64
+ # Send the essay to Groq API for feedback
65
  prompt = f"""
66
+ You are an expert academic writer with 40 years of experience in providing concise but effective feedback.
67
+ Instead of asking the student to do this and that, you just say replace this with this to improve concisely.
68
  Analyze the following essay: {user_input}.
69
  {st.session_state.plan} level user should get feedback specific to their level.
70
  """
 
77
  st.markdown("### Feedback")
78
  st.write(feedback)
79
 
80
+ # Provide improved version of the essay
81
  st.markdown("### Improved Version")
82
  st.write("Here's how your essay could look with the suggested improvements:")
83
  improved_prompt = f"Revise the following essay for {st.session_state.plan} level user: {user_input}"
 
91
  # Navigation for Next Day
92
  if "plan" in st.session_state and st.button("Next Day"):
93
  st.session_state.current_day += 1
94
+ if st.session_state.current_day > len(topics): # Reset to day 1 if all days are completed
95
+ st.session_state.current_day = 1
96
+ st.rerun() # Use st.experimental_rerun() to re-run the app and update the day and topic