dantedgp commited on
Commit
a61f3e4
·
1 Parent(s): 0e911e1

Deploying as pipeline

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +14 -24
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Question Generator
3
- emoji: 🐨
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: streamlit
 
1
  ---
2
  title: Question Generator
3
+ emoji: 🐉
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: streamlit
app.py CHANGED
@@ -1,47 +1,37 @@
1
  import streamlit as st
2
  import nltk
3
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
 
5
  # Initialize NLTK
6
  nltk.download('punkt')
7
  # Instantiate the model
8
- model = AutoModelForSeq2SeqLM.from_pretrained("dantedgp/question-generator")
9
- tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
10
-
11
- def generate_questions(txt):
12
- input_text = f"ask: {txt}"
13
- input_ids = tokenizer(input_text, return_tensors="pt").input_ids
14
- outputs = model.generate(input_ids, max_new_tokens=100, do_sample=False)
15
- question = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
-
17
- print('question: ', question)
18
- return question
19
 
20
  st.set_page_config(page_title='AI Quiz Generator')
21
  st.title('AI Quiz Generator')
 
22
  text_input = st.text_area(
23
  'Enter your text',
24
- value="""
25
- Algae cells can be used to synthesize lipids for the production of biofuels and foods.
26
  Integral transmembrane proteins shuttle nutrients in and out of the cell.
27
  Liver cells can metabolize poisons and alcohol.
28
  Chocolate helps the brain stay focused.
29
  Cellular respiration is the inverse of photosynthesis.
30
  Caffeine blocks adenosine receptors.
31
  Adenosine Triphosphate (ATP) is the ernergy currency of the cell.
32
- The mitochondria is the powerhouse of the cell.
33
- """,
34
  height=200
35
  )
36
 
37
  generate_button = st.button("Generate")
38
 
39
  if generate_button:
40
- if text_input != '':
41
- sentences = nltk.sent_tokenize(text_input)
42
- for sentence in sentences:
43
- question = generate_questions(sentence)
44
- st.write(question)
45
- else:
46
- st.warning('Please enter some text.')
47
-
 
 
1
  import streamlit as st
2
  import nltk
3
+ from transformers import pipeline
4
 
5
  # Initialize NLTK
6
  nltk.download('punkt')
7
  # Instantiate the model
8
+ model = pipeline(model="dantedgp/question-generator", tokenizer="google-t5/t5-small")
 
 
 
 
 
 
 
 
 
 
9
 
10
  st.set_page_config(page_title='AI Quiz Generator')
11
  st.title('AI Quiz Generator')
12
+
13
  text_input = st.text_area(
14
  'Enter your text',
15
+ value="""Algae cells can be used to synthesize lipids for the production of biofuels and foods.
 
16
  Integral transmembrane proteins shuttle nutrients in and out of the cell.
17
  Liver cells can metabolize poisons and alcohol.
18
  Chocolate helps the brain stay focused.
19
  Cellular respiration is the inverse of photosynthesis.
20
  Caffeine blocks adenosine receptors.
21
  Adenosine Triphosphate (ATP) is the ernergy currency of the cell.
22
+ The mitochondria is the powerhouse of the cell.""",
 
23
  height=200
24
  )
25
 
26
  generate_button = st.button("Generate")
27
 
28
  if generate_button:
29
+ sentences = nltk.sent_tokenize(text_input)
30
+ if not sentences:
31
+ st.warning('Please enter some text.')
32
+ for sentence in sentences:
33
+ try:
34
+ question = model(sentence)[0]['generated_text']
35
+ st.write(question)
36
+ except:
37
+ st.warning('An error occurred while generating the question.')