Number_to_words / app .py
Sonia2k5's picture
Rename app (5).py to app .py
b3fecfa verified
# -*- coding: utf-8 -*-
"""model.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1gCiedN3pbGAmSaO0KWH3Z2IFLcaZLwuw
"""
from huggingface_hub import hf_hub_download
import pickle
import gradio as gr
# Replace with your Hugging Face repo info
repo_id = "Sonia2k5/Number_to_words" # e.g., "syoga/image-classifier"
filename = "Number_to_word_model.pkl"
# Download the model from the hub
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
# Now `model` is ready to use
with open(model_path, "rb") as f:
model, le = pickle.load(f)
# Get input from the user, convert to integer, and reshape to a 2D array
try:
number_input = int(input("Enter a number: "))
encoded = model.predict([[number_input]])
word = le.inverse_transform(encoded)[0]
print(word)
except ValueError:
print("Invalid input. Please enter an integer.")
def predict_number_to_word(number):
if not isinstance(number, (int, float)):
return "Please enter a valid number."
if number < 1 or number > 1000:
return "❌ Please enter a number between 1 and 1000 only."
encoded = model.predict([[int(number)]])
word = le.inverse_transform(encoded)[0]
return f"{int(number)} β†’ {word}"
# Create Gradio interface
iface = gr.Interface(
fn=predict_number_to_word,
inputs=gr.Number(label="Enter a number (1 to 1000)"),
outputs=gr.Textbox(label="Number in Words"),
title="πŸ”’ Number to Word Converter",
description="Converts a number between 1 and 1000 to its English word using a Decision Tree model."
)
iface.launch()