Spaces:
Sleeping
Sleeping
Younesse Kaddar
commited on
Commit
Β·
3963768
1
Parent(s):
9a68a93
added GPT-4
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
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.
|
|
|
|
|
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,
|
@@ -24,20 +24,45 @@ from langchain.schema import (
|
|
24 |
SystemMessage
|
25 |
)
|
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...`")
|
@@ -61,12 +86,6 @@ def load_file(files):
|
|
61 |
if 'text' not in st.session_state:
|
62 |
st.session_state['text'] = ''
|
63 |
|
64 |
-
# Create models
|
65 |
-
claude = ChatAnthropic()
|
66 |
-
|
67 |
-
# Create retrieval chain
|
68 |
-
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3)
|
69 |
-
|
70 |
template="You are an expert problem statement reviewer with an expertise in getting A-levels students studying {subject} admitted to their dream university: {university}."
|
71 |
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
72 |
human_template="Can you give constructive criticism to improve my problem statement: {statement}"
|
|
|
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.vectorstores import FAISS
|
10 |
+
|
11 |
+
# from langchain.llms import OpenAI
|
12 |
from langchain.chat_models import ChatOpenAI, ChatAnthropic
|
|
|
13 |
from dotenv import load_dotenv, find_dotenv
|
|
|
14 |
from langchain.prompts import (
|
15 |
ChatPromptTemplate,
|
16 |
PromptTemplate,
|
|
|
24 |
SystemMessage
|
25 |
)
|
26 |
from io import StringIO
|
|
|
27 |
import PyPDF2
|
28 |
import docx
|
29 |
|
30 |
# Load environment variables
|
31 |
+
load_dotenv(find_dotenv())
|
|
|
|
|
|
|
|
|
32 |
|
|
|
33 |
st.set_page_config(page_title="AI Statement Reviewer", page_icon="π")
|
34 |
|
35 |
+
# Models for selection
|
36 |
+
models = ['GPT-3.5', 'GPT-4', 'Claude']
|
37 |
+
|
38 |
+
# Create models
|
39 |
+
chatgpt = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3)
|
40 |
+
gpt4 = ChatOpenAI(model_name="gpt-4", temperature=0.3)
|
41 |
+
claude = ChatAnthropic()
|
42 |
+
|
43 |
+
# Initialize session state
|
44 |
+
if 'model' not in st.session_state:
|
45 |
+
st.session_state['model'] = 'GPT-3.5-turbo'
|
46 |
+
|
47 |
+
# Get model based on user selection
|
48 |
+
selected_model = st.session_state['model']
|
49 |
+
if selected_model == 'GPT-3.5':
|
50 |
+
llm = chatgpt
|
51 |
+
elif selected_model == 'GPT-4':
|
52 |
+
llm = gpt4
|
53 |
+
elif selected_model == 'Claude':
|
54 |
+
llm = claude
|
55 |
+
|
56 |
+
# Add model selection to sidebar
|
57 |
+
st.sidebar.header('Select Model')
|
58 |
+
selected_model = st.sidebar.selectbox('Choose AI model', models)
|
59 |
+
st.session_state['model'] = selected_model
|
60 |
+
|
61 |
+
|
62 |
+
# Universities and Majors for selection
|
63 |
+
universities = ["Infer from statement", "University of Aberdeen", "Abertay University", "Aberystwyth University", "Anglia Ruskin University", "Arden University", "Arts University Bournemouth", "Aston University", "Bangor University", "Bath Spa University", "University of Bath", "University of Bedfordshire", "Birkbeck, University of London", "Birmingham City University", "University of Birmingham", "Bishop Grosseteste University", "University of Bolton", "Bournemouth University", "University of Brighton", "University of Bristol", "British Academy of Jewellery", "British College of Osteopathic Medicine", "Brunel University London", "University of Buckingham", "Buckinghamshire New University", "University of Cambridge", "Canterbury Christ Church University", "Cardiff Metropolitan University", "Cardiff University", "University of Chester", "University of Chichester", "City, University of London", "Coventry University", "Cranfield University", "University for the Creative Arts", "University of Cumbria", "De Montfort University", "University of Derby", "University of Dundee", "Durham University", "University of East Anglia", "University of East London", "Edge Hill University", "Edinburgh Napier University", "University of Edinburgh", "University of Essex", "University of Exeter", "Falmouth University", "Glasgow Caledonian University", "Glasgow School of Art", "University of Glasgow", "University of Gloucestershire", "Goldsmiths, University of London", "University of Greenwich", "Harper Adams University", "Heriot-Watt University", "University of Hertfordshire", "University of the Highlands and Islands", "University of Huddersfield", "University of Hull", "Imperial College London", "Keele University", "University of Kent", "King's College London, University of London", "Kingston University", "Lancaster University", "Leeds Arts University", "Leeds Beckett University", "Leeds Trinity University", "University of Leeds", "University of Leicester", "University of Lincoln", "Liverpool Hope University", "Liverpool Institute for Performing Arts", "Liverpool John Moores University", "University of Liverpool", "London Metropolitan University", "London School of Economics and Political Science, University of London", "London School of Hygiene and Tropical Medicine, University of London", "London South Bank University", "Loughborough University", "Manchester Metropolitan University", "University of Manchester", "Middlesex University", "Newcastle University", "Newman University", "University of Northampton", "Northeastern University", "University of Northumbria at Newcastle", "Norwich University of the Arts", "Nottingham Trent University", "University of Nottingham", "The Open University", "Oxford Brookes University", "University of Oxford", "University of Plymouth", "University of Portsmouth", "Queen Margaret University, Edinburgh", "Queen Mary University of London", "Queen's University Belfast", "Ravensbourne University London", "University of Reading", "Regent's University London", "Robert Gordon University", "University of Roehampton", "Rose Bruford College", "Royal Agricultural University", "Royal Central School of Speech and Drama", "Royal College of Art", "Royal College of Music", "Royal Conservatoire of Scotland", "Royal Holloway, University of London", "Royal Veterinary College, University of London", "University of Salford", "University of Sheffield", "Sheffield Hallam University", "University of South Wales", "University of Southampton", "University of St Andrews", "University of London St George's", "University of St Mark and St John", "University of Stirling", "University of Strathclyde", "University of Suffolk", "University of Sunderland", "University of Surrey", "University of Sussex", "Swansea University", "Teesside University", "Trinity Laban Conservatoire of Music and Dance", "Trinity Saint David, University of Wales", "Truro and Penwith College", "St Mary's University, Twickenham", "UCL (University College London)", "Ulster University", "University Campus Oldham", "University of Warwick", "University of Warwickshire", "University of the West of England, Bristol", "University of the West of Scotland", "University of Westminster", "University of Winchester", "Wirral Metropolitan College", "University of Wolverhampton", "University of Worcester", "Writtle University College", "York College", "York St John University", "University of York"]
|
64 |
+
majors = ["Infer from statement", "Accounting and Finance", "Aeronautical and Manufacturing Engineering", "Agriculture and Forestry", "Anatomy and Physiology", "Anthropology", "Archaeology", "Architecture", "Art and Design", "Biological Sciences", "Building", "Business and Management Studies", "Chemical Engineering", "Chemistry", "Civil Engineering", "Classics and Ancient History", "Communication and Media Studies", "Complementary Medicine", "Computer Science", "Counselling", "Creative Writing", "Criminology", "Dentistry", "Drama Dance and Cinematics", "Economics", "Education", "Electrical and Electronic Engineering", "English", "Fashion", "Film Making", "Food Science", "Forensic Science", "General Engineering", "Geography and Environmental Sciences", "Geology", "Health And Social Care", "History", "History of Art Architecture and Design", "Hospitality Leisure Recreation and Tourism", "Information Technology", "Land and Property Management", "Law", "Linguistics", "Marketing", "Materials Technology", "Mathematics", "Mechanical Engineering", "Medical Technology", "Medicine", "Music", "Nursing", "Occupational Therapy", "Pharmacology and Pharmacy", "Philosophy", "Physics and Astronomy", "Physiotherapy", "Politics", "Psychology", "Robotics", "Social Policy", "Social Work", "Sociology", "Sports Science", "Veterinary Medicine", "Youth Work"]
|
65 |
+
|
66 |
@st.cache_data
|
67 |
def load_file(files):
|
68 |
# st.info("`Analysing...`")
|
|
|
86 |
if 'text' not in st.session_state:
|
87 |
st.session_state['text'] = ''
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
template="You are an expert problem statement reviewer with an expertise in getting A-levels students studying {subject} admitted to their dream university: {university}."
|
90 |
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
91 |
human_template="Can you give constructive criticism to improve my problem statement: {statement}"
|