amyakir commited on
Commit
e34be93
·
verified ·
1 Parent(s): b9331aa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ # Load Hugging Face text generation pipeline
6
+ pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", device_map="auto", torch_dtype=torch.float16)
7
+
8
+ # Function to generate questions
9
+ def generate_questions(text):
10
+ prompt = f"Ask 5 short, simple comprehension questions about this English coursebook text:\n\n{text}"
11
+ output = pipe(prompt, max_new_tokens=200, do_sample=True)[0]["generated_text"]
12
+ return output.strip()
13
+
14
+ # Gradio Interface
15
+ demo = gr.Interface(fn=generate_questions, inputs="textbox", outputs="textbox", title="Coursebook Question Generator")
16
+
17
+ demo.launch()