-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubjectiveNET.py
More file actions
48 lines (36 loc) · 1.63 KB
/
Copy pathSubjectiveNET.py
File metadata and controls
48 lines (36 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as stl
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from dotenv import load_dotenv
from Llamacall import llm
def create_quiz_prompt_template():
system_message = """"
You are a teacher who is an excellent quiz maker. Your job is to create a quiz which only has Multiple Choice Questions.
Each quiz has {num_questions} questions based on the given context {context} .
You need to create all the questions relevant to the context, and make sure no question is repeated.
Each question has four possible options.
At the end of the quiz give all the answers together.
Only generate {num_questions} number of questions.
You generate text based mcqs on your own. You have to generate the quiz and only respond with the questions, their options and in the end give their answers, nothing else.
"""
prompt = PromptTemplate(
template=system_message,
input_variables=["num_questions", "context"]
)
return prompt
def create_quiz_chain(prompt, llm):
return LLMChain(llm=llm, prompt=prompt)
def app():
load_dotenv()
stl.write("Generate a context based quiz.")
prompt = create_quiz_prompt_template()
# repo_id = "tiiuae/falcon-7b-instruct"
# llm = HuggingFaceHub(
# repo_id = repo_id, model_kwargs={})
chain = create_quiz_chain(prompt, llm)
context = stl.text_area("Enter the context")
num_questions = stl.number_input(
"Enter the number of questions", min_value=1, max_value=100)
if stl.button("Generate quiz"):
quiz_response = chain.run(num_questions=num_questions, context=context)
stl.write(quiz_response)