File size: 1,633 Bytes
79e92a4 |
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 |
# -*- 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()
|