Spaces:
Running
Running
File size: 997 Bytes
2d25b12 3b8d910 2d25b12 3b8d910 2d25b12 3b8d910 2d25b12 |
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 30 |
from transformers import pipeline
# Load the Hugging Face pipeline
def load_model(task="summarization", framework="pt"):
"""
Load the specified task model using Hugging Face's pipeline.
Default is PyTorch ('pt') as the framework.
"""
model = pipeline(task=task, model="facebook/bart-large-cnn", framework=framework)
return model
# Summarization function
def summarize_text(model, text):
"""
Summarize the provided legal text.
"""
if not text.strip():
return "Please provide input text."
result = model(text, max_length=150, min_length=40, do_sample=False)
return result[0]['summary_text']
# Question Answering function
def answer_question(model, question, context):
"""
Answer a question based on the provided legal context.
"""
if not context.strip() or not question.strip():
return "Please provide both a context and a question."
result = model(question=question, context=context)
return result['answer'] |