Spaces:
Sleeping
Sleeping
Younesse Kaddar
commited on
Commit
β’
7e84f89
1
Parent(s):
b8cf9fa
new update
Browse files- app.py +67 -24
- app2.py +38 -1
- requirements.txt +2 -1
app.py
CHANGED
@@ -13,39 +13,82 @@ from langchain.chat_models import ChatOpenAI, ChatAnthropic
|
|
13 |
from langchain import PromptTemplate
|
14 |
from dotenv import load_dotenv, find_dotenv
|
15 |
|
16 |
-
load_dotenv(find_dotenv())
|
17 |
|
18 |
-
#
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
vectordb = Chroma.from_documents(comments, embedding=embeddings, persist_directory=".")
|
26 |
-
vectordb.persist()
|
27 |
-
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
|
|
37 |
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
|
|
42 |
|
43 |
-
|
44 |
-
grammar_result = grammar_qa({"question": user_input})
|
45 |
-
tips_result = tips_qa({"question": user_input})
|
46 |
-
st.write("Grammar and Structure Feedback:")
|
47 |
-
st.write(grammar_result["answer"])
|
48 |
-
st.write("Tips and Recommendations:")
|
49 |
-
st.write(tips_result["answer"])
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(statement, format="pdf"):
|
19 |
+
# Get the predictions from the AI model
|
20 |
+
predictions = model.predict(statement)
|
21 |
|
22 |
+
# Create a list of feedback
|
23 |
+
feedback = []
|
24 |
+
for prediction in predictions:
|
25 |
+
feedback.append(prediction["feedback"])
|
26 |
|
27 |
+
return feedback
|
|
|
|
|
|
|
28 |
|
29 |
+
# Create a function to display the feedback
|
30 |
+
def display_feedback(feedback):
|
31 |
+
st.header("π Here's your feedback:")
|
32 |
+
st.write(feedback)
|
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 |
+
This application uses AI to review and provide feedback on your university personal statement!
|
65 |
+
|
66 |
+
Here's what it does:
|
67 |
+
|
68 |
+
1. π§ **Review your grammar and structure**: The AI, powered by GPT-4, will check your statement for any grammatical or structural issues.
|
69 |
+
2. π‘ **Provide tips and recommendations**: Claude, another advanced AI, gives personalized tips and recommendations to make your statement even better.
|
70 |
+
|
71 |
+
This tool is part of Afinity.io's mission to democratize access to high-quality advice for students, no matter their background.
|
72 |
+
|
73 |
+
Just upload your personal statement below, and let our AI give you feedback!
|
74 |
+
""")
|
75 |
+
|
76 |
+
uploaded_file = st.file_uploader("Upload your personal statement here", type=["txt", "docx", "pdf"])
|
77 |
+
text_input = st.text_area("Or paste your personal statement here:")
|
78 |
+
|
79 |
+
if uploaded_file is not None:
|
80 |
+
statement = uploaded_file.read().decode()
|
81 |
+
file_type = uploaded_file.type.split('/')[1]
|
82 |
+
if st.button('Get feedback for uploaded file'):
|
83 |
+
feedback = get_feedback(statement, file_type)
|
84 |
+
display_feedback(feedback)
|
85 |
+
elif text_input:
|
86 |
+
if st.button('Get feedback for pasted text'):
|
87 |
+
feedback = get_feedback(text_input, "text")
|
88 |
+
display_feedback(feedback)
|
89 |
+
else:
|
90 |
+
st.write("π€ Please upload your personal statement or paste it into the text box.")
|
91 |
+
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
main()
|
app2.py
CHANGED
@@ -37,4 +37,41 @@ def main():
|
|
37 |
|
38 |
# Run the main function
|
39 |
if __name__ == "__main__":
|
40 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Run the main function
|
39 |
if __name__ == "__main__":
|
40 |
+
main()
|
41 |
+
|
42 |
+
# print("Start!")
|
43 |
+
# load_dotenv(find_dotenv())
|
44 |
+
|
45 |
+
# # pinecone.init(api_key=os.getenv("PINECONE_API_KEY"), environment=os.getenv("PINECONE_ENVIRONMENT"))
|
46 |
+
|
47 |
+
# dataset_path = "./dataset.txt"
|
48 |
+
# loader = TextLoader(dataset_path)
|
49 |
+
# comments = loader.load_and_split()
|
50 |
+
|
51 |
+
# embeddings = OpenAIEmbeddings(model_name="ada")
|
52 |
+
# vectordb = Chroma.from_documents(comments, embedding=embeddings, persist_directory=".")
|
53 |
+
# vectordb.persist()
|
54 |
+
# memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
55 |
+
|
56 |
+
# # Assuming that GPT-4 is used for grammar, structure, and fact-checking
|
57 |
+
# # and Claude is used for providing tips and encouraging students to do their own research
|
58 |
+
# grammar_llm = OpenAI(temperature=0.8)
|
59 |
+
# tips_llm = Claude(temperature=0.8)
|
60 |
+
|
61 |
+
# grammar_qa = ConversationalRetrievalChain.from_llm(grammar_llm, vectordb.as_retriever(), memory=memory)
|
62 |
+
# tips_qa = ConversationalRetrievalChain.from_llm(tips_llm, vectordb.as_retriever(), memory=memory)
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
# st.title('AI Statement Reviewer')
|
67 |
+
|
68 |
+
# user_input = st.text_area("Enter your personal statement here:")
|
69 |
+
|
70 |
+
# if st.button('Get feedback'):
|
71 |
+
# grammar_result = grammar_qa({"question": user_input})
|
72 |
+
# tips_result = tips_qa({"question": user_input})
|
73 |
+
# st.write("Grammar and Structure Feedback:")
|
74 |
+
# st.write(grammar_result["answer"])
|
75 |
+
# st.write("Tips and Recommendations:")
|
76 |
+
# st.write(tips_result["answer"])
|
77 |
+
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ anthropic
|
|
3 |
streamlit
|
4 |
langchain
|
5 |
python-dotenv
|
6 |
-
pinecone-client
|
|
|
|
3 |
streamlit
|
4 |
langchain
|
5 |
python-dotenv
|
6 |
+
pinecone-client
|
7 |
+
pypdf2
|