Spaces:
Running
Running
adding the feature of fill in the blank type of questions
Browse files
app.py
CHANGED
@@ -537,6 +537,14 @@ async def generate_questions_async(text, num_questions, context_window_size, num
|
|
537 |
st.error(f"An unexpected error occurred: {str(e)}")
|
538 |
return []
|
539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
540 |
async def process_batch(batch, keywords, context_window_size, num_beams):
|
541 |
questions = []
|
542 |
for text in batch:
|
@@ -544,6 +552,7 @@ async def process_batch(batch, keywords, context_window_size, num_beams):
|
|
544 |
for keyword, context in keyword_sentence_mapping.items():
|
545 |
question = await generate_question_async(context, keyword, num_beams)
|
546 |
options = await generate_options_async(keyword, context)
|
|
|
547 |
overall_score, relevance_score, complexity_score, spelling_correctness = assess_question_quality(context, question, keyword)
|
548 |
if overall_score >= 0.5:
|
549 |
questions.append({
|
@@ -555,6 +564,7 @@ async def process_batch(batch, keywords, context_window_size, num_beams):
|
|
555 |
"relevance_score": relevance_score,
|
556 |
"complexity_score": complexity_score,
|
557 |
"spelling_correctness": spelling_correctness,
|
|
|
558 |
})
|
559 |
return questions
|
560 |
|
@@ -639,6 +649,7 @@ def main():
|
|
639 |
show_options = st.checkbox("Options",False)
|
640 |
show_entity_link = st.checkbox("Entity Link For Wikipedia",True)
|
641 |
show_qa_scores = st.checkbox("QA Score",False)
|
|
|
642 |
num_beams = st.slider("Select number of beams for question generation", min_value=2, max_value=10, value=2)
|
643 |
context_window_size = st.slider("Select context window size (number of sentences before and after)", min_value=1, max_value=5, value=1)
|
644 |
num_questions = st.slider("Select number of questions to generate", min_value=1, max_value=1000, value=5)
|
@@ -696,6 +707,8 @@ def main():
|
|
696 |
for i, q in enumerate(state['generated_questions']):
|
697 |
st.subheader(body=f":orange[Q{i+1}:] {q['question']}")
|
698 |
|
|
|
|
|
699 |
if show_context is True:
|
700 |
st.write(f"**Context:** {q['context']}")
|
701 |
if show_answer is True:
|
|
|
537 |
st.error(f"An unexpected error occurred: {str(e)}")
|
538 |
return []
|
539 |
|
540 |
+
async def generate_fill_in_the_blank_questions(context,answer):
|
541 |
+
answerSize = len(answer)
|
542 |
+
replacedBlanks = ""
|
543 |
+
for i in range(answerSize):
|
544 |
+
replacedBlanks += "_"
|
545 |
+
blank_q = context.replace(answer,replacedBlanks)
|
546 |
+
return blank_q
|
547 |
+
|
548 |
async def process_batch(batch, keywords, context_window_size, num_beams):
|
549 |
questions = []
|
550 |
for text in batch:
|
|
|
552 |
for keyword, context in keyword_sentence_mapping.items():
|
553 |
question = await generate_question_async(context, keyword, num_beams)
|
554 |
options = await generate_options_async(keyword, context)
|
555 |
+
blank_question = await generate_fill_in_the_blank_questions(context,keyword)
|
556 |
overall_score, relevance_score, complexity_score, spelling_correctness = assess_question_quality(context, question, keyword)
|
557 |
if overall_score >= 0.5:
|
558 |
questions.append({
|
|
|
564 |
"relevance_score": relevance_score,
|
565 |
"complexity_score": complexity_score,
|
566 |
"spelling_correctness": spelling_correctness,
|
567 |
+
"blank_question": blank_question,
|
568 |
})
|
569 |
return questions
|
570 |
|
|
|
649 |
show_options = st.checkbox("Options",False)
|
650 |
show_entity_link = st.checkbox("Entity Link For Wikipedia",True)
|
651 |
show_qa_scores = st.checkbox("QA Score",False)
|
652 |
+
show_blank_question = st.checkbox("Fill in the Blank Questions",True)
|
653 |
num_beams = st.slider("Select number of beams for question generation", min_value=2, max_value=10, value=2)
|
654 |
context_window_size = st.slider("Select context window size (number of sentences before and after)", min_value=1, max_value=5, value=1)
|
655 |
num_questions = st.slider("Select number of questions to generate", min_value=1, max_value=1000, value=5)
|
|
|
707 |
for i, q in enumerate(state['generated_questions']):
|
708 |
st.subheader(body=f":orange[Q{i+1}:] {q['question']}")
|
709 |
|
710 |
+
if show_blank_question is True:
|
711 |
+
st.write(f"**Fill in the Blank Question:** {q['blank_question']}")
|
712 |
if show_context is True:
|
713 |
st.write(f"**Context:** {q['context']}")
|
714 |
if show_answer is True:
|