Spaces:
Sleeping
Sleeping
Younesse Kaddar
commited on
Commit
Β·
631a94c
1
Parent(s):
7e84f89
new version
Browse files- .env.example +1 -0
- app.py +103 -76
- app3.py +87 -0
.env.example
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
OPENAI_API_KEY=
|
|
|
2 |
PINECONE_ENV=
|
3 |
PINECONE_API_KEY=
|
|
|
1 |
OPENAI_API_KEY=
|
2 |
+
ANTHROPIC_API_KEY=
|
3 |
PINECONE_ENV=
|
4 |
PINECONE_API_KEY=
|
app.py
CHANGED
@@ -1,94 +1,121 @@
|
|
1 |
import os
|
2 |
-
import pinecone
|
3 |
import streamlit as st
|
4 |
-
from langchain.document_loaders import
|
5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
6 |
-
from langchain.embeddings import OpenAIEmbeddings
|
7 |
-
from langchain.vectorstores import Chroma
|
8 |
-
from langchain.chains import ConversationalRetrievalChain, LLMChain
|
9 |
from langchain.memory import ConversationBufferMemory
|
10 |
from langchain.llms import OpenAI
|
11 |
-
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
|
12 |
from langchain.chat_models import ChatOpenAI, ChatAnthropic
|
13 |
from langchain import PromptTemplate
|
14 |
from dotenv import load_dotenv, find_dotenv
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
return feedback
|
28 |
|
29 |
-
# Create a function to display the feedback
|
30 |
def display_feedback(feedback):
|
31 |
-
st.
|
32 |
-
|
33 |
-
|
34 |
-
# Create a main function
|
35 |
-
def main():
|
36 |
-
"""
|
37 |
-
AI Statement Reviewer App
|
38 |
-
|
39 |
-
This application uses OpenAI's GPT-4 and Anthropic's Claude language models, along with the LangChain framework, to provide an AI-driven statement review service for students applying to universities.
|
40 |
-
|
41 |
-
The app reviews student personal statements and gives feedback on several aspects:
|
42 |
-
1. Grammar and Structure: The app evaluates the grammar and structural integrity of the personal statement, providing suggestions for improvement where necessary.
|
43 |
-
2. Tips and Recommendations: The app gives personalized tips and recommendations, encouraging students to engage in their own research and further study.
|
44 |
-
|
45 |
-
The application is designed to democratize access to high-quality personal statement advice, providing feedback that was previously only available to a select few. The ultimate goal is to enhance social mobility and level the playing field for all students, regardless of their background.
|
46 |
-
|
47 |
-
This application is a part of Afinity.io's suite of student advice services, which aim to provide comprehensive guidance to students choosing courses at the university level. It is also an important step towards Afinity.io's vision for 2030: to have every student make informed study choices through the Afinity platform.
|
48 |
-
"""
|
49 |
-
|
50 |
-
load_dotenv(find_dotenv())
|
51 |
-
|
52 |
-
st.set_page_config(
|
53 |
-
page_title="AI Statement Reviewer",
|
54 |
-
page_icon="π",
|
55 |
-
layout="centered",
|
56 |
-
initial_sidebar_state="expanded",
|
57 |
-
)
|
58 |
|
59 |
-
st.title('π AI Statement Reviewer π')
|
60 |
-
|
61 |
-
st.header('By Afinity.io')
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
st.markdown("""
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
display_feedback(feedback)
|
85 |
elif text_input:
|
86 |
-
if st.button(
|
87 |
-
feedback = get_feedback(text_input
|
88 |
display_feedback(feedback)
|
89 |
else:
|
90 |
-
st.write("
|
91 |
-
|
92 |
-
|
93 |
-
if __name__ == "__main__":
|
94 |
-
main()
|
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
3 |
+
from langchain.document_loaders import PyPDFLoader, Docx2txtLoader
|
4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
5 |
+
from langchain.embeddings import OpenAIEmbeddings
|
6 |
+
from langchain.vectorstores import Chroma
|
7 |
+
from langchain.chains import ConversationalRetrievalChain, LLMChain
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from langchain.llms import OpenAI
|
|
|
10 |
from langchain.chat_models import ChatOpenAI, ChatAnthropic
|
11 |
from langchain import PromptTemplate
|
12 |
from dotenv import load_dotenv, find_dotenv
|
13 |
+
from langchain import PromptTemplate
|
14 |
+
from langchain.prompts import (
|
15 |
+
ChatPromptTemplate,
|
16 |
+
PromptTemplate,
|
17 |
+
SystemMessagePromptTemplate,
|
18 |
+
AIMessagePromptTemplate,
|
19 |
+
HumanMessagePromptTemplate,
|
20 |
+
)
|
21 |
+
from langchain.schema import (
|
22 |
+
AIMessage,
|
23 |
+
HumanMessage,
|
24 |
+
SystemMessage
|
25 |
+
)
|
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.extractText() for page in pdf_reader.pages])
|
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 pdf file.', icon="β οΈ")
|
50 |
+
return text
|
51 |
+
|
52 |
+
# Initialize session state
|
53 |
+
if 'text' not in st.session_state:
|
54 |
+
st.session_state['text'] = ''
|
55 |
+
|
56 |
+
# Create models
|
57 |
+
claude = ChatAnthropic()
|
58 |
+
|
59 |
+
# Create retrieval chain
|
60 |
+
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3)
|
61 |
+
|
62 |
+
template="You are an expert problem statement reviewer with an expertise in getting A-levels students studying {subject} admitted to their dream university: {university}."
|
63 |
+
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
64 |
+
human_template="Can you give constructive criticism to improve my problem statement: {statement}"
|
65 |
+
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
66 |
+
|
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="English", university="Oxford University", statement=text, verbose=True)
|
74 |
+
print(feedback)
|
75 |
return feedback
|
76 |
|
|
|
77 |
def display_feedback(feedback):
|
78 |
+
st.write("π Here is the AI feedback:")
|
79 |
+
# Style the feedback
|
80 |
+
st.markdown(f'<p style="font-size: 20px">{feedback}</p>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
|
|
|
|
82 |
|
83 |
+
def main():
|
84 |
+
# Set page title and icon
|
85 |
+
st.title("π AI Statement Reviewer π")
|
86 |
+
|
87 |
+
# Add description
|
88 |
+
st.header('β¨ By Affinity.io β¨')
|
89 |
st.markdown("""
|
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()
|
|
|
|
app3.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pinecone
|
3 |
+
import streamlit as st
|
4 |
+
from langchain.document_loaders import TextLoader, PyPDFLoader, Docx2txtLoader
|
5 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
6 |
+
from langchain.embeddings import OpenAIEmbeddings
|
7 |
+
from langchain.vectorstores import Chroma, Pinecone
|
8 |
+
from langchain.chains import ConversationalRetrievalChain, LLMChain, SimpleSequentialChain
|
9 |
+
from langchain.memory import ConversationBufferMemory
|
10 |
+
from langchain.llms import OpenAI
|
11 |
+
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
|
12 |
+
from langchain.chat_models import ChatOpenAI, ChatAnthropic
|
13 |
+
from langchain import PromptTemplate
|
14 |
+
from dotenv import load_dotenv, find_dotenv
|
15 |
+
|
16 |
+
|
17 |
+
# Create a function to get the feedback from the AI model
|
18 |
+
def get_feedback(file, format=".pdf"):
|
19 |
+
# Get the predictions from the AI model
|
20 |
+
|
21 |
+
# Not implemented yet
|
22 |
+
|
23 |
+
# Create a function to display the feedback
|
24 |
+
def display_feedback(feedback):
|
25 |
+
st.header("π Here's your feedback:")
|
26 |
+
st.write(feedback)
|
27 |
+
|
28 |
+
# Create a main function
|
29 |
+
def main():
|
30 |
+
"""
|
31 |
+
AI Statement Reviewer App
|
32 |
+
|
33 |
+
This application provides an AI-driven statement review service for students applying to universities.
|
34 |
+
|
35 |
+
The app reviews student personal statements and gives feedback on several aspects:
|
36 |
+
1. Grammar and Structure: The app evaluates the grammar and structural integrity of the personal statement, providing suggestions for improvement where necessary.
|
37 |
+
2. Tips and Recommendations: The app gives personalized tips and recommendations, encouraging students to engage in their own research and further study.
|
38 |
+
|
39 |
+
The application is designed to democratize access to high-quality personal statement advice, providing feedback that was previously only available to a select few. The ultimate goal is to enhance social mobility and level the playing field for all students, regardless of their background.
|
40 |
+
|
41 |
+
This application is a part of Afinity.io's suite of student advice services, which aim to provide comprehensive guidance to students choosing courses at the university level. It is also an important step towards Afinity.io's vision for 2030: to have every student make informed study choices through the Afinity platform.
|
42 |
+
"""
|
43 |
+
|
44 |
+
load_dotenv(find_dotenv())
|
45 |
+
|
46 |
+
st.set_page_config(
|
47 |
+
page_title="AI Statement Reviewer",
|
48 |
+
page_icon="π",
|
49 |
+
layout="centered",
|
50 |
+
initial_sidebar_state="expanded",
|
51 |
+
)
|
52 |
+
|
53 |
+
st.title('π AI Statement Reviewer π')
|
54 |
+
|
55 |
+
st.header('By Afinity.io')
|
56 |
+
|
57 |
+
st.markdown("""
|
58 |
+
This application uses AI to review and provide feedback on your university personal statement!
|
59 |
+
|
60 |
+
Here's what it does:
|
61 |
+
|
62 |
+
1. π§ **Review your grammar and structure**: The AI, powered by GPT-4, will check your statement for any grammatical or structural issues.
|
63 |
+
2. π‘ **Provide tips and recommendations**: Claude, another advanced AI, gives personalized tips and recommendations to make your statement even better.
|
64 |
+
|
65 |
+
This tool is part of Afinity.io's mission to democratize access to high-quality advice for students, no matter their background.
|
66 |
+
|
67 |
+
Just upload your personal statement below, and let our AI give you feedback!
|
68 |
+
""")
|
69 |
+
|
70 |
+
uploaded_file = st.file_uploader("Upload your personal statement here", type=["txt", "docx", "pdf"])
|
71 |
+
text_input = st.text_area("Or paste your personal statement here:")
|
72 |
+
|
73 |
+
if uploaded_file is not None:
|
74 |
+
file_type = uploaded_file.type.split('/')[1]
|
75 |
+
if st.button('Get feedback for uploaded file'):
|
76 |
+
feedback = get_feedback(uploaded_file, file_type)
|
77 |
+
display_feedback(feedback)
|
78 |
+
elif text_input:
|
79 |
+
if st.button('Get feedback for pasted text'):
|
80 |
+
feedback = get_feedback(text_input, "string")
|
81 |
+
display_feedback(feedback)
|
82 |
+
else:
|
83 |
+
st.write("π€ Please upload your personal statement or paste it into the text box.")
|
84 |
+
|
85 |
+
|
86 |
+
if __name__ == "__main__":
|
87 |
+
main()
|