Spaces:
No application file
No application file
Download arithmetic_model.py from geethareddy/tooth: direct link, hf CLI and curl.
- Browser
- Download file 775 Bytes
-
https://huggingface.co/spaces/geethareddy/tooth/resolve/main/arithmetic_model.py
- Command line
-
hf download hf://spaces/geethareddy/tooth/arithmetic_model.py
-
curl -L -o arithmetic_model.py https://huggingface.co/spaces/geethareddy/tooth/resolve/main/arithmetic_model.py
775 Bytes
| 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() | |