Spaces:
Sleeping
Sleeping
Younesse Kaddar
commited on
Commit
Β·
9a68a93
1
Parent(s):
631a94c
new update
Browse files- app.py +21 -19
- requirements.txt +2 -1
app.py
CHANGED
@@ -26,27 +26,35 @@ from langchain.schema import (
|
|
26 |
from io import StringIO
|
27 |
from langchain.vectorstores import FAISS
|
28 |
import PyPDF2
|
|
|
29 |
|
30 |
# Load environment variables
|
31 |
load_dotenv(find_dotenv())
|
32 |
|
|
|
|
|
|
|
|
|
33 |
# Set page config
|
34 |
st.set_page_config(page_title="AI Statement Reviewer", page_icon="π")
|
35 |
|
36 |
@st.cache_data
|
37 |
def load_file(files):
|
38 |
-
st.info("`Analysing...`")
|
39 |
text = ""
|
40 |
for file_path in files:
|
41 |
file_extension = os.path.splitext(file_path.name)[1]
|
42 |
if file_extension == ".pdf":
|
43 |
pdf_reader = PyPDF2.PdfReader(file_path)
|
44 |
-
text += "".join([page.
|
45 |
elif file_extension == ".txt":
|
46 |
stringio = StringIO(file_path.getvalue().decode("utf-8"))
|
47 |
text += stringio.read()
|
|
|
|
|
|
|
48 |
else:
|
49 |
-
st.warning('Please provide a text or
|
50 |
return text
|
51 |
|
52 |
# Initialize session state
|
@@ -67,10 +75,10 @@ human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
|
67 |
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
|
68 |
chain = LLMChain(llm=llm, prompt=chat_prompt)
|
69 |
|
70 |
-
def get_feedback(text):
|
71 |
# Use a loading screen
|
72 |
with st.spinner('π Generating feedback...'):
|
73 |
-
feedback = chain.predict(subject=
|
74 |
print(feedback)
|
75 |
return feedback
|
76 |
|
@@ -86,36 +94,30 @@ def main():
|
|
86 |
|
87 |
# Add description
|
88 |
st.header('β¨ By Affinity.io β¨')
|
89 |
-
|
90 |
-
This application uses advanced AI to review and provide feedback on your university personal statement! π¨βππ©βπ
|
91 |
-
|
92 |
-
Here's what it does:
|
93 |
-
|
94 |
-
1. π§ **Review your grammar and structure**: Our AI, powered by OpenAI's Davinci and Anthropic's Claude, will check your statement
|
95 |
-
for grammar and structure, helping you present your ideas clearly and effectively.
|
96 |
-
2. π‘ **Provide useful tips and recommendations**: The AI will provide insightful tips to strengthen your statement.
|
97 |
-
3. π **Support for all students**: Our goal is to provide high-quality, personalized feedback to students from all backgrounds.
|
98 |
-
|
99 |
-
Just upload your statement or paste it in the box below, and let's get started! π
|
100 |
-
""")
|
101 |
|
102 |
# Get file or text input
|
103 |
uploaded_file = st.file_uploader("π Upload your personal statement here", type=["pdf","docx","txt"], accept_multiple_files=True)
|
104 |
text_input = st.text_area("π¬ Or enter your personal statement here:", value=st.session_state['text'])
|
105 |
st.session_state['text'] = text_input
|
106 |
|
|
|
|
|
|
|
|
|
107 |
# Get and display feedback
|
108 |
if uploaded_file is not None:
|
109 |
# Load text from file
|
110 |
text = load_file(uploaded_file)
|
111 |
if st.button("π Get Feedback"):
|
112 |
-
feedback = get_feedback(text)
|
113 |
display_feedback(feedback)
|
114 |
elif text_input:
|
115 |
if st.button("π Get Feedback"):
|
116 |
-
feedback = get_feedback(text_input)
|
117 |
display_feedback(feedback)
|
118 |
else:
|
119 |
st.write("Please upload a file or enter your personal statement to get feedback. π")
|
|
|
120 |
if __name__ == "__main__":
|
121 |
main()
|
|
|
26 |
from io import StringIO
|
27 |
from langchain.vectorstores import FAISS
|
28 |
import PyPDF2
|
29 |
+
import docx
|
30 |
|
31 |
# Load environment variables
|
32 |
load_dotenv(find_dotenv())
|
33 |
|
34 |
+
# Universities and Majors for selection
|
35 |
+
universities = ['Oxford University', 'St Andrews University', 'Warwick University', 'University of Sheffield', 'University of Cambridge', 'Infer from statement']
|
36 |
+
majors = ['English', 'Computer Science', 'Engineering', 'Mathematics', 'Biology', 'Infer from statement']
|
37 |
+
|
38 |
# Set page config
|
39 |
st.set_page_config(page_title="AI Statement Reviewer", page_icon="π")
|
40 |
|
41 |
@st.cache_data
|
42 |
def load_file(files):
|
43 |
+
# st.info("`Analysing...`")
|
44 |
text = ""
|
45 |
for file_path in files:
|
46 |
file_extension = os.path.splitext(file_path.name)[1]
|
47 |
if file_extension == ".pdf":
|
48 |
pdf_reader = PyPDF2.PdfReader(file_path)
|
49 |
+
text += "".join([page.extract_text() for page in pdf_reader.pages])
|
50 |
elif file_extension == ".txt":
|
51 |
stringio = StringIO(file_path.getvalue().decode("utf-8"))
|
52 |
text += stringio.read()
|
53 |
+
elif file_extension == ".docx":
|
54 |
+
doc = docx.Document(file_path)
|
55 |
+
text += " ".join([paragraph.text for paragraph in doc.paragraphs])
|
56 |
else:
|
57 |
+
st.warning('Please provide a text, pdf or docx file.', icon="β οΈ")
|
58 |
return text
|
59 |
|
60 |
# Initialize session state
|
|
|
75 |
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
|
76 |
chain = LLMChain(llm=llm, prompt=chat_prompt)
|
77 |
|
78 |
+
def get_feedback(text, university, major):
|
79 |
# Use a loading screen
|
80 |
with st.spinner('π Generating feedback...'):
|
81 |
+
feedback = chain.predict(subject=major, university=university, statement=text, verbose=True)
|
82 |
print(feedback)
|
83 |
return feedback
|
84 |
|
|
|
94 |
|
95 |
# Add description
|
96 |
st.header('β¨ By Affinity.io β¨')
|
97 |
+
# your markdown...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
# Get file or text input
|
100 |
uploaded_file = st.file_uploader("π Upload your personal statement here", type=["pdf","docx","txt"], accept_multiple_files=True)
|
101 |
text_input = st.text_area("π¬ Or enter your personal statement here:", value=st.session_state['text'])
|
102 |
st.session_state['text'] = text_input
|
103 |
|
104 |
+
# Get university and major
|
105 |
+
chosen_university = st.selectbox('ποΈ Select your University', universities)
|
106 |
+
chosen_major = st.selectbox('π Select your Major', majors)
|
107 |
+
|
108 |
# Get and display feedback
|
109 |
if uploaded_file is not None:
|
110 |
# Load text from file
|
111 |
text = load_file(uploaded_file)
|
112 |
if st.button("π Get Feedback"):
|
113 |
+
feedback = get_feedback(text, chosen_university, chosen_major)
|
114 |
display_feedback(feedback)
|
115 |
elif text_input:
|
116 |
if st.button("π Get Feedback"):
|
117 |
+
feedback = get_feedback(text_input, chosen_university, chosen_major)
|
118 |
display_feedback(feedback)
|
119 |
else:
|
120 |
st.write("Please upload a file or enter your personal statement to get feedback. π")
|
121 |
+
|
122 |
if __name__ == "__main__":
|
123 |
main()
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ streamlit
|
|
4 |
langchain
|
5 |
python-dotenv
|
6 |
pinecone-client
|
7 |
-
pypdf2
|
|
|
|
4 |
langchain
|
5 |
python-dotenv
|
6 |
pinecone-client
|
7 |
+
pypdf2
|
8 |
+
python-docx
|