File size: 642 Bytes
ace7592
b985953
ace7592
 
 
 
 
622f41b
b985953
3d98aa9
ace7592
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622f41b
ace7592
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from transformers import pipeline

qa_pipeline = pipeline(
    "text2text-generation",
    model="google/flan-t5-large",
    device=0 if torch.cuda.is_available() else -1
)

def generate_answer(context, question):
    prompt = f"""
    You are a helpful research assistant. Use the context to answer the question.
    
    Context:
    {context}
    
    Question: {question}
    
    Answer in a comprehensive paragraph with key details:
    """
    
    result = qa_pipeline(
        prompt,
        max_length=512,
        do_sample=True,
        temperature=0.7,
        top_p=0.9
    )
    
    return result[0]['generated_text'].strip()