Rasif78 commited on
Commit
e46bf2b
1 Parent(s): bdd5117

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +53 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ctransformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load pre-trained model and tokenizer
5
+ model_name = "gpt2"
6
+ model = AutoModelForCausalLM.from_pretrained("TheBloke/dolphin-2.2.1-mistral-7B-GGUF", model_file="dolphin-2.2.1-mistral-7b.Q4_K_M.gguf", model_type="mistral", gpu_layers=50)
7
+ tokenizer = AutoTokenizer.from_pretrained("TheBloke/dolphin-2.2.1-mistral-7B-GGUF")
8
+
9
+ def generate_mcqs(paragraph):
10
+ sentences = paragraph.split('. ')
11
+ mcqs = []
12
+
13
+ for sentence in sentences:
14
+ if sentence:
15
+ prompt = f"Generate a multiple-choice question based on the following sentence: {sentence}"
16
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
17
+ outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
18
+ question = tokenizer.decode(outputs[0], skip_special_tokens=True)
19
+
20
+ # Generate options (this is a simplified example)
21
+ options = ["Option A", "Option B", "Option C", "Option D"]
22
+ correct_answer = options[0]
23
+
24
+ mcqs.append({
25
+ "mcq": question,
26
+ "options": {
27
+ "a": options[0],
28
+ "b": options[1],
29
+ "c": options[2],
30
+ "d": options[3]
31
+ },
32
+ "correct": "a"
33
+ })
34
+
35
+ return mcqs
36
+
37
+ # Streamlit UI
38
+ st.title("MCQ Generator")
39
+ st.write("Enter a paragraph to generate multiple-choice questions.")
40
+
41
+ paragraph = st.text_area("Paragraph", height=200)
42
+ if st.button("Generate MCQs"):
43
+ if paragraph:
44
+ mcqs = generate_mcqs(paragraph)
45
+ for i, mcq in enumerate(mcqs):
46
+ st.write(f"**Question {i+1}:** {mcq['mcq']}")
47
+ st.write(f"a. {mcq['options']['a']}")
48
+ st.write(f"b. {mcq['options']['b']}")
49
+ st.write(f"c. {mcq['options']['c']}")
50
+ st.write(f"d. {mcq['options']['d']}")
51
+ st.write(f"**Correct Answer:** {mcq['correct']}")
52
+ else:
53
+ st.write("Please enter a paragraph.")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ ctransformers