Upload 2 files
Browse files- model.py +53 -0
- requirements.txt +3 -0
model.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""model.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1gCiedN3pbGAmSaO0KWH3Z2IFLcaZLwuw
|
8 |
+
"""
|
9 |
+
|
10 |
+
from huggingface_hub import hf_hub_download
|
11 |
+
import pickle
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
# Replace with your Hugging Face repo info
|
15 |
+
repo_id = "Sonia2k5/Number_to_words" # e.g., "syoga/image-classifier"
|
16 |
+
filename = "Number_to_word_model.pkl"
|
17 |
+
|
18 |
+
# Download the model from the hub
|
19 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
20 |
+
|
21 |
+
# Now `model` is ready to use
|
22 |
+
with open(model_path, "rb") as f:
|
23 |
+
model, le = pickle.load(f)
|
24 |
+
|
25 |
+
# Get input from the user, convert to integer, and reshape to a 2D array
|
26 |
+
try:
|
27 |
+
number_input = int(input("Enter a number: "))
|
28 |
+
encoded = model.predict([[number_input]])
|
29 |
+
word = le.inverse_transform(encoded)[0]
|
30 |
+
print(word)
|
31 |
+
except ValueError:
|
32 |
+
print("Invalid input. Please enter an integer.")
|
33 |
+
|
34 |
+
def predict_number_to_word(number):
|
35 |
+
if not isinstance(number, (int, float)):
|
36 |
+
return "Please enter a valid number."
|
37 |
+
if number < 1 or number > 1000:
|
38 |
+
return "❌ Please enter a number between 1 and 1000 only."
|
39 |
+
encoded = model.predict([[int(number)]])
|
40 |
+
word = le.inverse_transform(encoded)[0]
|
41 |
+
return f"{int(number)} → {word}"
|
42 |
+
|
43 |
+
# Create Gradio interface
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=predict_number_to_word,
|
46 |
+
inputs=gr.Number(label="Enter a number (1 to 1000)"),
|
47 |
+
outputs=gr.Textbox(label="Number in Words"),
|
48 |
+
title="🔢 Number to Word Converter",
|
49 |
+
description="Converts a number between 1 and 1000 to its English word using a Decision Tree model."
|
50 |
+
)
|
51 |
+
|
52 |
+
iface.launch()
|
53 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|