Spaces:
Sleeping
Sleeping
Update hf_model.py
Browse files- hf_model.py +14 -2
hf_model.py
CHANGED
|
@@ -1,12 +1,19 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
# Load the Hugging Face pipeline
|
| 4 |
-
def load_model(task="summarization"):
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
return model
|
| 7 |
|
| 8 |
# Summarization function
|
| 9 |
def summarize_text(model, text):
|
|
|
|
|
|
|
|
|
|
| 10 |
if not text.strip():
|
| 11 |
return "Please provide input text."
|
| 12 |
result = model(text, max_length=150, min_length=40, do_sample=False)
|
|
@@ -14,5 +21,10 @@ def summarize_text(model, text):
|
|
| 14 |
|
| 15 |
# Question Answering function
|
| 16 |
def answer_question(model, question, context):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
result = model(question=question, context=context)
|
| 18 |
return result['answer']
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
# Load the Hugging Face pipeline
|
| 4 |
+
def load_model(task="summarization", framework="pt"):
|
| 5 |
+
"""
|
| 6 |
+
Load the specified task model using Hugging Face's pipeline.
|
| 7 |
+
Default is PyTorch ('pt') as the framework.
|
| 8 |
+
"""
|
| 9 |
+
model = pipeline(task=task, model="facebook/bart-large-cnn", framework=framework)
|
| 10 |
return model
|
| 11 |
|
| 12 |
# Summarization function
|
| 13 |
def summarize_text(model, text):
|
| 14 |
+
"""
|
| 15 |
+
Summarize the provided legal text.
|
| 16 |
+
"""
|
| 17 |
if not text.strip():
|
| 18 |
return "Please provide input text."
|
| 19 |
result = model(text, max_length=150, min_length=40, do_sample=False)
|
|
|
|
| 21 |
|
| 22 |
# Question Answering function
|
| 23 |
def answer_question(model, question, context):
|
| 24 |
+
"""
|
| 25 |
+
Answer a question based on the provided legal context.
|
| 26 |
+
"""
|
| 27 |
+
if not context.strip() or not question.strip():
|
| 28 |
+
return "Please provide both a context and a question."
|
| 29 |
result = model(question=question, context=context)
|
| 30 |
return result['answer']
|