File size: 1,874 Bytes
312d328 04e6faf 312d328 7a53b85 312d328 ee9798d 34cfb85 04e6faf 312d328 34cfb85 312d328 34cfb85 ee9798d 34cfb85 ee9798d 312d328 04e6faf 312d328 7a53b85 04e6faf 7a53b85 312d328 04e6faf 312d328 146153c 312d328 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import gradio as gr
# Mapping of letters to digits as per a standard phone keypad
keypad_mapping = {
"A": "2",
"B": "2",
"C": "2",
"D": "3",
"E": "3",
"F": "3",
"G": "4",
"H": "4",
"I": "4",
"J": "5",
"K": "5",
"L": "5",
"M": "6",
"N": "6",
"O": "6",
"P": "7",
"Q": "7",
"R": "7",
"S": "7",
"T": "8",
"U": "8",
"V": "8",
"W": "9",
"X": "9",
"Y": "9",
"Z": "9",
}
# Function to convert the phone number
def convert_phone_number(phone_number, trim_to_10):
numerical_phone_number = ""
digit_count = 0
ignore_first_digit = phone_number.startswith("1")
for char in phone_number:
if char.isalpha():
numerical_phone_number += keypad_mapping[char.upper()]
if not ignore_first_digit:
digit_count += 1
ignore_first_digit = False
else:
numerical_phone_number += char
if char.isdigit() and not (ignore_first_digit and digit_count == 0):
digit_count += 1
ignore_first_digit = False
if trim_to_10 and digit_count >= 10:
break
return numerical_phone_number
# Create Gradio interface
iface = gr.Interface(
fn=convert_phone_number,
inputs=[
gr.Textbox(label="Enter Phone Number with Letters"),
gr.Checkbox(label="Trim to 10 digits"),
],
outputs=gr.Textbox(label="Numerical Phone Number"),
examples=[
["1-800-TEDDYSC", True],
["1-800-MY-APPLE", False],
["1-800-Fidelity", True],
],
title="Phone Number Converter | Made by <a href='https://teddysc.me'>Teddy</a>",
description="Convert a phone number with letters to its numerical equivalent. For example, '1-800-TEDDYSC' becomes '1-800-8333972'.",
)
# Launch the app
iface.launch(
share=True,
)
|