File size: 775 Bytes
82de934
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline

# Load a pre-trained model for text generation (e.g., GPT-2 or GPT-3)
model = "gpt2"
arithmetic_model = pipeline("text-generation", model=model)

def perform_arithmetic(operation):
    # Send the arithmetic operation as input to the model
    result = arithmetic_model(operation, max_length=50, num_return_sequences=1)
    return result[0]['generated_text']

def main():
    # Example operations
    operations = [
        "What is 5 plus 3?",
        "What is 10 minus 4?",
        "Calculate 15 + 7",
        "Subtract 9 from 20"
    ]
    
    for operation in operations:
        print(f"Operation: {operation}")
        result = perform_arithmetic(operation)
        print(f"Result: {result}\n")

if __name__ == "__main__":
    main()