MIRNA-MOUKHTAR2025 commited on
Commit
f492d76
Β·
verified Β·
1 Parent(s): 5f43f70

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -1,26 +1,19 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # βœ… Use the correct pipeline task
5
  question_generator = pipeline("text2text-generation", model="valhalla/t5-base-e2e-qg")
6
 
7
  def generate_questions(text):
8
- # Split text into chunks (optional)
9
- chunks = text.split(". ")
10
- questions = []
11
- for chunk in chunks:
12
- if len(chunk.strip()) > 0:
13
- result = question_generator(chunk, max_length=64)[0]['generated_text']
14
- questions.append(f"❓ {result}")
15
- return "\n".join(questions)
16
 
17
- # Gradio interface
18
- interface = gr.Interface(
19
  fn=generate_questions,
20
- inputs=gr.Textbox(lines=15, placeholder="Paste your long text here..."),
21
  outputs="text",
22
- title="πŸ” Generate Questions from Text",
23
- description="Uses a T5 model to generate questions from a multi-sentence paragraph."
24
  )
25
 
26
- interface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Correct pipeline task
5
  question_generator = pipeline("text2text-generation", model="valhalla/t5-base-e2e-qg")
6
 
7
  def generate_questions(text):
8
+ inputs = f"generate questions: {text}"
9
+ outputs = question_generator(inputs, max_length=256, do_sample=False)
10
+ return outputs[0]["generated_text"]
 
 
 
 
 
11
 
12
+ iface = gr.Interface(
 
13
  fn=generate_questions,
14
+ inputs=gr.Textbox(lines=10, label="Enter your paragraph"),
15
  outputs="text",
16
+ title="πŸ” Generate Questions from Text"
 
17
  )
18
 
19
+ iface.launch()