Abdul-Rheman commited on
Commit
ab36abf
·
verified ·
1 Parent(s): fb0f95b

Rename learn_engapp.py to app.py

Browse files
Files changed (2) hide show
  1. app.py +83 -0
  2. learn_engapp.py +0 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
14
+ st.subheader("Improve your English Writing Skills with AI-powered Feedback")
15
+
16
+ # Plans Section
17
+ st.markdown("### Choose Your Plan:")
18
+ col1, col2, col3 = st.columns(3)
19
+
20
+ with col1:
21
+ st.subheader("30 Days Plan")
22
+ st.write("Focus on key areas of improvement daily.")
23
+ if st.button("Select 30 Days Plan"):
24
+ st.session_state.plan = "30 Days"
25
+
26
+ with col2:
27
+ st.subheader("45 Days Plan")
28
+ st.write("Build advanced writing skills over time.")
29
+ if st.button("Select 45 Days Plan"):
30
+ st.session_state.plan = "45 Days"
31
+
32
+ with col3:
33
+ st.subheader("60 Days Plan")
34
+ st.write("Achieve mastery with detailed feedback.")
35
+ if st.button("Select 60 Days Plan"):
36
+ st.session_state.plan = "60 Days"
37
+
38
+ # Display selected plan and current day
39
+ 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
+ """
61
+ chat_completion = client.chat.completions.create(
62
+ messages=[{"role": "user", "content": prompt}],
63
+ model="llama3-8b-8192",
64
+ )
65
+ feedback = chat_completion.choices[0].message.content
66
+ st.success("Feedback Generated!")
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}"
73
+ improved_completion = client.chat.completions.create(
74
+ messages=[{"role": "user", "content": improved_prompt}],
75
+ model="llama3-8b-8192",
76
+ )
77
+ improved_essay = improved_completion.choices[0].message.content
78
+ st.write(improved_essay)
79
+
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()
learn_engapp.py DELETED
File without changes