Spaces:
No application file
No application file
| 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() | |