Working Questgen implemented
Browse filesFiles changed (3)
- .gitignore+3-1
- app.py+54-19
- requirements.txt+4-1
1234venv.vscodes2v_reddit_2015_md.tar.gz__pycache__123456venv.vscodes2v_reddit_2015_md.tar.gz__pycache__s2v_old._s2v_old
1231 unmodified line567891031 unmodified lines424344454647484950515253545556575859606162636465663 unmodified lines70717273747576777879import timeimport gradio as grfrom transformers import AutoTokenizer1 unmodified linefrom pathlib import Pathfrom FastT5 import get_onnx_runtime_sessions, OnnxT5trained_model_path = './t5_squad_v1/'31 unmodified linesdec = [tknizer.decode(ids, skip_special_tokens=True) for ids in outs]Question = dec[0].replace("question:", "")Ouestion = Question.strip()return Question# context = "Ramsri loves to watch cricket during his free time"# answer = "cricket"context = "Donald Trump is an American media personality and businessman who served as the 45th president of the United States."answer = "Donald Trump"ques = get_question(context, answer, model, tokenizer)print("question: ", ques)context = gr.components.Textbox(lines=5, placeholder="Enter paragraph/context here...")answer = gr.components.Textbox(lines=3, placeholder="Enter answer/keyword here...")question = gr.components.Textbox(type="text", label="Question")def generate_question(context, answer):start_time = time.time() # Record the start timeresult = get_question(context, answer, model, tokenizer)3 unmodified linesreturn resultiface = gr.Interface(fn=generate_question,inputs=[context, answer],outputs=question)iface.launch()123451 unmodified line7891011121314151617181920212223242531 unmodified lines575859606162636465663 unmodified lines707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import pkefrom sense2vec import Sense2Vecimport timeimport gradio as grfrom transformers import AutoTokenizer1 unmodified linefrom pathlib import Pathfrom FastT5 import get_onnx_runtime_sessions, OnnxT5commands = ["curl -LO https://github.com/explosion/sense2vec/releases/download/v1.0.0/s2v_reddit_2015_md.tar.gz","tar -xvf s2v_reddit_2015_md.tar.gz",]for command in commands:return_code = os.system(command)if return_code == 0:print(f"Command '{command}' executed successfully")else:print(f"Command '{command}' failed with return code {return_code}")s2v = Sense2Vec().from_disk("s2v_old")trained_model_path = './t5_squad_v1/'31 unmodified linesdec = [tknizer.decode(ids, skip_special_tokens=True) for ids in outs]Question = dec[0].replace("question:", "")Question = Question.strip()return Questiondef generate_question(context, answer):start_time = time.time() # Record the start timeresult = get_question(context, answer, model, tokenizer)3 unmodified linesreturn resultdef generate_mcq(context):extractor = pke.unsupervised.TopicRank()extractor.load_document(input=context, language='en')extractor.candidate_selection(pos={"NOUN", "PROPN", "ADJ"})extractor.candidate_weighting()keyphrases = extractor.get_n_best(n=10)results = []for keyword, _ in keyphrases:original_keyword = keywordkeyword = original_keyword.lower().replace(" ", "_")sense = s2v.get_best_sense(keyword)if sense is not None:most_similar = s2v.most_similar(sense, n=2)distractors = [word.split("|")[0].lower().replace("_", " ") for word, _ in most_similar]question = generate_question(context, original_keyword)result = {"Question": question,"Keyword": original_keyword,"Distractor1": distractors[0],"Distractor2": distractors[1]}results.append(result)return resultsiface = gr.Interface(fn=generate_mcq,inputs=gr.Textbox(label="Context", type='text'),outputs=gr.JSON(value=list),title="Questgen AI",description="Enter a context to generate MCQs for keywords.")iface.launch()
4 unmodified lines56784 unmodified linestransformerssentencepieceprogresspsutil4 unmodified lines5678910114 unmodified linestransformerssentencepieceprogresspsutilsense2vecgit+https://github.com/boudinfl/pke.giten-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.6.0/en_core_web_sm-3.6.0-py3-none-any.whl
.gitignore+3-1
app.py+54-19
requirements.txt+4-1