Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,33 +17,26 @@ with open('Response.json', 'r') as file:
|
|
17 |
|
18 |
st.title("MCQs Creator Application")
|
19 |
|
20 |
-
def
|
21 |
-
return df
|
22 |
-
|
23 |
-
|
24 |
-
det = fetch(df)
|
25 |
-
|
26 |
-
def download():
|
27 |
-
|
28 |
col1, col2 = st.columns(2)
|
29 |
|
30 |
if button:
|
31 |
if col1.button("Download CSV"):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
)
|
38 |
|
39 |
-
if col2.button("Download
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
)
|
46 |
-
|
47 |
with st.form("user_inputs"):
|
48 |
uploader_file = st.file_uploader("Upload a PDF or Txt file")
|
49 |
mcq_count = st.text_input("No. of MCQS")
|
@@ -51,6 +44,8 @@ with st.form("user_inputs"):
|
|
51 |
tone = st.text_input("Complexity Level of Questions", max_chars=20, placeholder="Simple")
|
52 |
button = st.form_submit_button("Create MCQs")
|
53 |
|
|
|
|
|
54 |
if button and uploader_file is not None and mcq_count and subject and tone:
|
55 |
with st.spinner("loading..."):
|
56 |
try:
|
@@ -82,14 +77,16 @@ with st.form("user_inputs"):
|
|
82 |
if table_data is not None:
|
83 |
df = pd.DataFrame(table_data)
|
84 |
df.index = df.index + 1
|
85 |
-
fetch(df)
|
86 |
st.table(df)
|
87 |
# Display the review in a text box as well
|
88 |
st.text_area(label="Review", value=response["review"])
|
89 |
# Call the download function
|
|
|
90 |
else:
|
91 |
st.error("Error in the table data")
|
92 |
else:
|
93 |
st.write(response)
|
94 |
|
95 |
-
|
|
|
|
|
|
17 |
|
18 |
st.title("MCQs Creator Application")
|
19 |
|
20 |
+
def download(df):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
col1, col2 = st.columns(2)
|
22 |
|
23 |
if button:
|
24 |
if col1.button("Download CSV"):
|
25 |
+
csv_data = df.to_csv(index=False).encode("utf-8")
|
26 |
+
st.download_button(data=csv_data,
|
27 |
+
file_name="generated_mcqs.csv",
|
28 |
+
key="csv-download",
|
29 |
+
help="Click to download as CSV"
|
30 |
)
|
31 |
|
32 |
+
if col2.button("Download PDF"):
|
33 |
+
pdf_data = df.to_html().encode("utf-8")
|
34 |
+
st.download_button(data=pdf_data,
|
35 |
+
file_name="generated_mcqs.pdf",
|
36 |
+
key="pdf-download",
|
37 |
+
help="Click to download as PDF"
|
38 |
)
|
39 |
+
|
40 |
with st.form("user_inputs"):
|
41 |
uploader_file = st.file_uploader("Upload a PDF or Txt file")
|
42 |
mcq_count = st.text_input("No. of MCQS")
|
|
|
44 |
tone = st.text_input("Complexity Level of Questions", max_chars=20, placeholder="Simple")
|
45 |
button = st.form_submit_button("Create MCQs")
|
46 |
|
47 |
+
df = None # Declare df at a broader scope
|
48 |
+
|
49 |
if button and uploader_file is not None and mcq_count and subject and tone:
|
50 |
with st.spinner("loading..."):
|
51 |
try:
|
|
|
77 |
if table_data is not None:
|
78 |
df = pd.DataFrame(table_data)
|
79 |
df.index = df.index + 1
|
|
|
80 |
st.table(df)
|
81 |
# Display the review in a text box as well
|
82 |
st.text_area(label="Review", value=response["review"])
|
83 |
# Call the download function
|
84 |
+
|
85 |
else:
|
86 |
st.error("Error in the table data")
|
87 |
else:
|
88 |
st.write(response)
|
89 |
|
90 |
+
# Now you can use df outside the form if needed
|
91 |
+
if df is not None:
|
92 |
+
download(df)
|