Raghu-Shikari commited on
Commit
dc4b7c7
·
verified ·
1 Parent(s): 648d0d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,17 +1,24 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- # Load the Hugging Face model for text generation
5
- pipe = pipeline("text-generation", model="google/gemma-2-27b-it")
6
 
7
- # Function to generate MCQs
8
  def generate_mcqs(content, num_questions):
9
- messages = [{"role": "user", "content": content}]
10
- questions = pipe(messages, max_length=512, num_return_sequences=num_questions, num_beams=num_questions)
 
 
 
 
 
 
 
11
  return questions
12
 
13
  # Streamlit UI
14
- st.title("MCQ Generator using Hugging Face")
15
 
16
  content = st.text_area("Enter the content from which MCQs will be generated:", height=200)
17
  num_questions = st.number_input("Enter the number of MCQs to generate:", min_value=1, max_value=20, value=5, step=1)
@@ -20,7 +27,7 @@ if st.button("Generate MCQs"):
20
  if content:
21
  mcqs = generate_mcqs(content, num_questions)
22
  for i, mcq in enumerate(mcqs):
23
- st.write(f"Q{i+1}: {mcq['generated_text']}")
24
  else:
25
  st.warning("Please enter the content to generate MCQs.")
26
 
@@ -28,3 +35,4 @@ if st.button("Generate MCQs"):
28
 
29
 
30
 
 
 
1
  import streamlit as st
2
+ import openai
3
 
4
+ # Set the API key
5
+ openai.api_key = "sk-proj-uHasdgbriPPlFMm99ZtJT3BlbkFJOl231YfdxCSNmQjVEpMX"
6
 
7
+ # Function to generate MCQs using OpenAI
8
  def generate_mcqs(content, num_questions):
9
+ response = openai.Completion.create(
10
+ engine="davinci-codex", # You can use a different engine if needed
11
+ prompt=f"Generate {num_questions} multiple-choice questions from the following content:\n\n{content}\n\n",
12
+ max_tokens=500,
13
+ n=num_questions,
14
+ stop=None,
15
+ temperature=0.7
16
+ )
17
+ questions = [choice["text"].strip() for choice in response.choices]
18
  return questions
19
 
20
  # Streamlit UI
21
+ st.title("MCQ Generator using OpenAI")
22
 
23
  content = st.text_area("Enter the content from which MCQs will be generated:", height=200)
24
  num_questions = st.number_input("Enter the number of MCQs to generate:", min_value=1, max_value=20, value=5, step=1)
 
27
  if content:
28
  mcqs = generate_mcqs(content, num_questions)
29
  for i, mcq in enumerate(mcqs):
30
+ st.write(f"Q{i+1}: {mcq}")
31
  else:
32
  st.warning("Please enter the content to generate MCQs.")
33
 
 
35
 
36
 
37
 
38
+