|
from transformers import pipeline |
|
|
|
|
|
def authenticate(api_key): |
|
|
|
|
|
|
|
|
|
|
|
model_gpt = pipeline("text-generation", model="EleutherAI/gpt-neo-125M") |
|
|
|
|
|
model_t5 = pipeline("text2text-generation", model="t5-base") |
|
|
|
|
|
model_bert = pipeline("fill-mask", model="bert-base-uncased") |
|
|
|
return model_gpt, model_t5, model_bert |
|
|
|
|
|
def process_step(step, text, api_key): |
|
|
|
model_gpt, model_t5, model_bert = authenticate(api_key) |
|
|
|
|
|
if step == 1: |
|
|
|
gpt_result = model_gpt(text, max_length=100) |
|
return gpt_result |
|
elif step == 2: |
|
|
|
t5_result = model_t5(text) |
|
return t5_result |
|
elif step == 3: |
|
|
|
bert_result = model_bert(text) |
|
return bert_result |
|
else: |
|
return "Unknown step" |
|
|
|
|
|
if __name__ == "__main__": |
|
api_key = "your_api_key_here" |
|
|
|
text_input = "Your text input here." |
|
|
|
|
|
step = 1 |
|
result = process_step(step, text_input, api_key) |
|
print(f"Result from step {step}: {result}") |
|
|
|
|
|
step = 2 |
|
result = process_step(step, text_input, api_key) |
|
print(f"Result from step {step}: {result}") |
|
|
|
|
|
step = 3 |
|
result = process_step(step, text_input, api_key) |
|
print(f"Result from step {step}: {result}") |