Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,68 +23,63 @@ with st.form("user_inputs"):
|
|
23 |
subject = st.text_input("Insert subject", max_chars=20)
|
24 |
tone = st.text_input("Complexity Level of Questions", max_chars=20, placeholder="Simple")
|
25 |
button = st.form_submit_button("Create MCQs")
|
26 |
-
download()
|
27 |
|
28 |
-
if button and
|
29 |
with st.spinner("loading..."):
|
30 |
try:
|
31 |
-
text=read_file(
|
32 |
-
#Count tokens and the cost of API call
|
33 |
with get_openai_callback() as cb:
|
34 |
-
response=generate_evaluate_chain(
|
35 |
{
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
)
|
43 |
-
#st.write(response)
|
44 |
-
|
45 |
except Exception as e:
|
46 |
traceback.print_exception(type(e), e, e.__traceback__)
|
47 |
st.error("Error")
|
48 |
-
|
49 |
else:
|
50 |
print(f"Total Tokens:{cb.total_tokens}")
|
51 |
print(f"Prompt Tokens:{cb.prompt_tokens}")
|
52 |
print(f"Completion Tokens:{cb.completion_tokens}")
|
53 |
print(f"Total Cost:{cb.total_cost}")
|
54 |
if isinstance(response, dict):
|
55 |
-
#Extract the quiz data from the response
|
56 |
-
quiz=response.get("quiz", None)
|
57 |
if quiz is not None:
|
58 |
-
table_data=get_table_data(quiz)
|
59 |
if table_data is not None:
|
60 |
-
df=pd.DataFrame(table_data)
|
61 |
-
df.index=df.index+1
|
|
|
62 |
st.table(df)
|
63 |
-
#Display the review in
|
64 |
st.text_area(label="Review", value=response["review"])
|
|
|
|
|
65 |
else:
|
66 |
st.error("Error in the table data")
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
def download():
|
72 |
-
if button:
|
73 |
-
csv_filename = "generated_mcqs.csv"
|
74 |
-
pdf_filename = "generated_mcqs.pdf"
|
75 |
-
|
76 |
-
csv = st.download_button(
|
77 |
-
label="Download as CSV",
|
78 |
-
data=df.to_csv(index=False).encode("utf-8"),
|
79 |
-
file_name=csv_filename,
|
80 |
-
key="csv-download",
|
81 |
-
)
|
82 |
-
|
83 |
-
pdf = st.download_button(
|
84 |
-
label="Download as PDF",
|
85 |
-
data=df.to_html().encode("utf-8"),
|
86 |
-
file_name=pdf_filename,
|
87 |
-
key="pdf-download",
|
88 |
-
)
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
subject = st.text_input("Insert subject", max_chars=20)
|
24 |
tone = st.text_input("Complexity Level of Questions", max_chars=20, placeholder="Simple")
|
25 |
button = st.form_submit_button("Create MCQs")
|
|
|
26 |
|
27 |
+
if button and uploader_file is not None and mcq_count and subject and tone:
|
28 |
with st.spinner("loading..."):
|
29 |
try:
|
30 |
+
text = read_file(uploader_file)
|
31 |
+
# Count tokens and the cost of the API call
|
32 |
with get_openai_callback() as cb:
|
33 |
+
response = generate_evaluate_chain(
|
34 |
{
|
35 |
+
"text": text,
|
36 |
+
"number": mcq_count,
|
37 |
+
"subject": subject,
|
38 |
+
"tone": tone,
|
39 |
+
"response_json": json.dumps(RESPONSE_JSON)
|
40 |
+
}
|
41 |
)
|
|
|
|
|
42 |
except Exception as e:
|
43 |
traceback.print_exception(type(e), e, e.__traceback__)
|
44 |
st.error("Error")
|
|
|
45 |
else:
|
46 |
print(f"Total Tokens:{cb.total_tokens}")
|
47 |
print(f"Prompt Tokens:{cb.prompt_tokens}")
|
48 |
print(f"Completion Tokens:{cb.completion_tokens}")
|
49 |
print(f"Total Cost:{cb.total_cost}")
|
50 |
if isinstance(response, dict):
|
51 |
+
# Extract the quiz data from the response
|
52 |
+
quiz = response.get("quiz", None)
|
53 |
if quiz is not None:
|
54 |
+
table_data = get_table_data(quiz)
|
55 |
if table_data is not None:
|
56 |
+
df = pd.DataFrame(table_data)
|
57 |
+
df.index = df.index + 1
|
58 |
+
download(df)
|
59 |
st.table(df)
|
60 |
+
# Display the review in a text box as well
|
61 |
st.text_area(label="Review", value=response["review"])
|
62 |
+
# Call the download function
|
63 |
+
|
64 |
else:
|
65 |
st.error("Error in the table data")
|
66 |
+
else:
|
67 |
+
st.write(response)
|
68 |
|
69 |
+
def download(df):
|
70 |
+
csv_filename = "generated_mcqs.csv"
|
71 |
+
pdf_filename = "generated_mcqs.pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
csv = st.download_button(
|
74 |
+
label="Download as CSV",
|
75 |
+
data=df.to_csv(index=False).encode("utf-8"),
|
76 |
+
file_name=csv_filename,
|
77 |
+
key="csv-download",
|
78 |
+
)
|
79 |
|
80 |
+
pdf = st.download_button(
|
81 |
+
label="Download as PDF",
|
82 |
+
data=df.to_html().encode("utf-8"),
|
83 |
+
file_name=pdf_filename,
|
84 |
+
key="pdf-download",
|
85 |
+
)
|