miiiciiii commited on
Commit
5045a3d
1 Parent(s): 112a666

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
2
+
3
+ # Load the model and tokenizer
4
+ model = T5ForConditionalGeneration.from_pretrained("miiiciiii/I-Comprehend_qg")
5
+ tokenizer = T5Tokenizer.from_pretrained("miiiciiii/I-Comprehend_qg")
6
+
7
+ def get_question(context, answer, model, tokenizer):
8
+ """Generate a question for the given answer and context."""
9
+ answer_span = context.replace(answer, f"<hl>{answer}<hl>", 1) + "</s>"
10
+ inputs = tokenizer(answer_span, return_tensors="pt")
11
+ question = model.generate(input_ids=inputs.input_ids, max_length=50)[0]
12
+
13
+ return tokenizer.decode(question, skip_special_tokens=True)
14
+
15
+ # Define the context and answer
16
+ context = "The Eiffel Tower is located in Paris and is one of the most famous landmarks in the world."
17
+ answer = "Eiffel Tower"
18
+
19
+ # Generate the question
20
+ question = get_question(context, answer, model, tokenizer)
21
+ print("Generated Question:", question)