Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,59 +23,68 @@ 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 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
response = generate_evaluate_chain({
|
36 |
-
"text": text,
|
37 |
-
"number": mcq_count,
|
38 |
-
"subject": subject,
|
39 |
-
"tone": tone,
|
40 |
-
"response_json": json.dumps(RESPONSE_JSON)
|
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 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
st.text_area(label="Review", value=response["review"])
|
61 |
-
else:
|
62 |
-
st.error("Error in the table data")
|
63 |
else:
|
64 |
st.write(response)
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
|
81 |
|
|
|
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 uploaded_file is not None and mcq_count and subject and tone:
|
29 |
+
with st.spinner("loading..."):
|
30 |
+
try:
|
31 |
+
text=read_file(uploaded_file)
|
32 |
+
#Count tokens and the cost of API call
|
33 |
+
with get_openai_callback() as cb:
|
34 |
+
response=generate_evaluate_chain(
|
35 |
+
{
|
36 |
+
"text": text,
|
37 |
+
"number": mcq_count,
|
38 |
+
"subject":subject,
|
39 |
+
"tone": tone,
|
40 |
+
"response_json": json.dumps(RESPONSE_JSON)
|
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 atext box as well
|
64 |
+
st.text_area(label="Review", value=response["review"])
|
65 |
+
else:
|
66 |
+
st.error("Error in the table data")
|
67 |
|
|
|
|
|
|
|
68 |
else:
|
69 |
st.write(response)
|
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 |
|