-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
114 lines (105 loc) · 3.55 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import streamlit as st
import pandas as pd
import time
from rag import *
from llm import *
from scapper import *
from recommender import *
from st_aggrid import AgGrid
from st_aggrid.grid_options_builder import GridOptionsBuilder
from st_aggrid import GridUpdateMode, DataReturnMode
st.set_page_config(
page_title="CP/DSA QUESTION SOLVER",
layout="wide",
initial_sidebar_state="expanded",
)
st.sidebar.title('CP/DSA QUESTION SOLVER')
def get_answer(language):
answer = f"This is a simulated answer for the given question in '{language}'"
return answer
st.markdown(
"""
<style>
section[data-testid="stSidebar"] {
width: 500px !important; # Set the width to your desired value
}
</style>
""",
unsafe_allow_html=True,
)
#st.title("CP/DSA Solver")
st.sidebar.subheader('Select type of question')
question_type = st.sidebar.selectbox(
"Select type:",
("Codeforces","Leetcode","Others")
)
#question_type = st.selectbox("Choose the type of question you would like to enter:", ("Select","CodeForces", "Leetcode", "Others"))
if question_type in ("CodeForces", "Leetcode"):
question_number = st.sidebar.text_input("Enter question number:")
# Language dropdown
language_options = ("C++", "Java", "Python")
language = st.sidebar.selectbox("Choose language:", language_options)
data = load_data(language)
embed = mod()
database = retriever(embed,data)
else:
question = st.sidebar.text_input("Enter your question:")
language = None
submit = st.sidebar.button("Submit")
if submit:
if(question_type == "Leetcode"):
if(question_number in data["index"]):
question = scrape_leetcode(question_number)
answer = leetcode(question,database)
else:
question = scrapeL(question_number)
answer = leetcode(question,database)
elif(question_type == "Codeforces"):
question, tag_lst, Rating = scrapecf(question_number)
answer = codeforces_problem(question)
else:
answer = new_problem(question)
# Clear layout for better presentation (optional)
st.empty()
container = st.container(border=True)
container.write("### Solution")
container.markdown(
"""
<style>.
[data-testid="container"]:nth-child(2){
background-color: lightgrey;
}
</style>
""",
unsafe_allow_html=True
)
# Create two columns for clear output display
with container:
st.divider()
col1, col2 = st.columns(2)
with col1:
st.write("*Your question:*")
if question_type in ("Leetcode", "CodeForces"):
st.write(f"Question number " + question_number)
else:
st.write(question)
with col2:
st.write("*Answer:*")
st.write(answer)
st.write("##")
container1 = st.container(border=True)
container1.write("### Recommender System")
with container1:
st.divider()
st.write("The following are the similar questions we recommend you attempt next:")
if(question_type == "Leetcode" or "Others"):
docs = RecommenderL(question,database)
for i in range(5):
st.write("Question "+i)
st.write(docs[i].page_content)
st.write(" ")
else:
problems = recommend_cf(Rating,tag_lst)
for i in problems:
st.write(i)
st.write(" ")