File size: 665 Bytes
e34be93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
import torch
from transformers import pipeline

# Load Hugging Face text generation pipeline
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", device_map="auto", torch_dtype=torch.float16)

# Function to generate questions
def generate_questions(text):
    prompt = f"Ask 5 short, simple comprehension questions about this English coursebook text:\n\n{text}"
    output = pipe(prompt, max_new_tokens=200, do_sample=True)[0]["generated_text"]
    return output.strip()

# Gradio Interface
demo = gr.Interface(fn=generate_questions, inputs="textbox", outputs="textbox", title="Coursebook Question Generator")

demo.launch()