Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
|
| 4 |
-
#
|
| 5 |
model_name = "iarfmoose/t5-base-question-generator"
|
| 6 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 7 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
|
| 9 |
-
# Генерация вопроса только по контексту
|
| 10 |
def generate_question(context):
|
| 11 |
prompt = f"generate question: {context}"
|
| 12 |
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).input_ids
|
|
@@ -14,7 +13,6 @@ def generate_question(context):
|
|
| 14 |
question = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 15 |
return question
|
| 16 |
|
| 17 |
-
# Интерфейс
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=generate_question,
|
| 20 |
inputs=gr.Textbox(label="Context", placeholder="Enter paragraph...", lines=5),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
|
| 4 |
+
# Дообученная модель для генерации вопросов
|
| 5 |
model_name = "iarfmoose/t5-base-question-generator"
|
| 6 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 7 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
|
|
|
|
| 9 |
def generate_question(context):
|
| 10 |
prompt = f"generate question: {context}"
|
| 11 |
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512).input_ids
|
|
|
|
| 13 |
question = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 14 |
return question
|
| 15 |
|
|
|
|
| 16 |
demo = gr.Interface(
|
| 17 |
fn=generate_question,
|
| 18 |
inputs=gr.Textbox(label="Context", placeholder="Enter paragraph...", lines=5),
|