miiiciiii commited on
Commit
afa22c9
verified
1 Parent(s): 5199d4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
2
+ import torch
3
+
4
+ # Load the model and tokenizer
5
+ t5ag_model = T5ForConditionalGeneration.from_pretrained("miiiciiii/I-Comprehend_ag")
6
+ t5ag_tokenizer = T5Tokenizer.from_pretrained("miiiciiii/I-Comprehend_ag")
7
+
8
+ def answer_question(question, context):
9
+ """Generate an answer for a given question and context."""
10
+ input_text = f"question: {question} context: {context}"
11
+ input_ids = t5ag_tokenizer.encode(input_text, return_tensors="pt", max_length=512, truncation=True)
12
+
13
+ with torch.no_grad():
14
+ output = t5ag_model.generate(input_ids, max_length=512, num_return_sequences=1, max_new_tokens=200)
15
+
16
+ return t5ag_tokenizer.decode(output[0], skip_special_tokens=True)
17
+
18
+ # Example usage
19
+ question = "What is the location of the Eiffel Tower?"
20
+ context = "The Eiffel Tower is located in Paris and is one of the most famous landmarks in the world."
21
+ answer = answer_question(question, context)
22
+ print("Generated Answer:", answer)