Spaces:
Sleeping
Sleeping
File size: 1,908 Bytes
25c2584 45ff63a 25c2584 45ff63a 25c2584 7dead73 45ff63a |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# models.py
from transformers import pipeline
# Load all models here
def load_sentiment_model():
"""Loads the sentiment analysis model."""
return pipeline(
"sentiment-analysis",
model="distilbert-base-uncased-finetuned-sst-2-english",
device=-1 # Force CPU
)
def load_summarization_model():
"""Loads the text summarization model."""
return pipeline(
"summarization",
model="sshleifer/distilbart-cnn-12-6",
device=-1 # Force CPU
)
def load_translation_model():
"""Loads the English to French translation model."""
return pipeline(
"translation_en_to_fr",
model="t5-small",
device=-1 # Force CPU
)
# New model loading functions
def load_question_answering_model():
"""Loads a question answering model."""
return pipeline(
"question-answering",
model="distilbert-base-cased-distilled-squad",
device=-1 # Force CPU
)
def load_text_generation_model():
"""Loads a text generation model."""
return pipeline(
"text-generation",
model="gpt2",
device=-1 # Force CPU
)
def load_ner_model():
"""Loads a named entity recognition model."""
return pipeline(
"ner",
model="dbmdz/bert-large-cased-finetuned-conll03-english",
aggregation_strategy="simple",
device=-1 # Force CPU
)
def load_text_classification_model():
"""Loads a zero-shot classification model."""
return pipeline(
"zero-shot-classification",
model="facebook/bart-large-mnli",
device=-1 # Force CPU
)
# Remove text-to-sql model for now to fix the import error
# def load_text_to_sql_model():
# """Loads a text-to-SQL model."""
# return pipeline(
# "text2text-generation",
# model="mrm8488/t5-base-finetuned-wikiSQL",
# device=-1 # Force CPU
# ) |