Spaces:
Sleeping
Sleeping
Download app.py from DevaMalla/advancedmath: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/DevaMalla/advancedmath/resolve/main/app.py
- Command line
-
hf download hf://spaces/DevaMalla/advancedmath/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DevaMalla/advancedmath/resolve/main/app.py
1.28 kB
| import gradio as gr | |
| def prime_factors(n): | |
| """ | |
| Compute the prime factorization of a positive integer. | |
| Args: | |
| n (int): The integer to factorize. Must be greater than 1. | |
| Returns: | |
| List[int]: A list of prime factors in ascending order. | |
| Raises: | |
| ValueError: If n is not greater than 1. | |
| """ | |
| n = int(n) | |
| if n <= 1: | |
| raise ValueError("Input must be an integer greater than 1.") | |
| factors = [] | |
| while n % 2 == 0: | |
| factors.append(2) | |
| n //= 2 | |
| divisor = 3 | |
| while divisor * divisor <= n: | |
| while n % divisor == 0: | |
| factors.append(divisor) | |
| n //= divisor | |
| divisor += 2 | |
| if n > 1: | |
| factors.append(n) | |
| return factors | |
| # def letter_counter(word, letter): | |
| # """Count the occurrences of a specific letter in a word. | |
| # Args: | |
| # word: The word or phrase to analyze | |
| # letter: The letter to count occurrences of | |
| # Returns: | |
| # The number of times the letter appears in the word | |
| # """ | |
| # return word.lower().count(letter.lower()) + 100 | |
| demo = gr.Interface( | |
| fn=prime_factors, | |
| inputs=["text"], | |
| outputs="text", | |
| title="Prime Factors", | |
| description="Prime Factors" | |
| ) | |
| demo.launch(mcp_server=True) |