Spaces:
Sleeping
Sleeping
kurniawan
commited on
Commit
·
7791531
1
Parent(s):
02e7c0e
Convert to Gradio app
Browse files- .gitignore +1 -0
- README.md +2 -2
- app.py +20 -8
- requirements.txt +1 -1
- ziko.py +85 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
README.md
CHANGED
|
@@ -3,8 +3,8 @@ title: Simple Input Output App
|
|
| 3 |
emoji: 🚀
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
-
sdk:
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 3 |
emoji: 🚀
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -1,11 +1,23 @@
|
|
| 1 |
-
import
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
if
|
| 8 |
-
|
| 9 |
-
st.write(f"You entered: **{user_input}**")
|
| 10 |
-
st.write(f"Character count: {len(user_input)}")
|
| 11 |
-
st.write(f"Word count: {len(user_input.split())}")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
|
| 3 |
+
def process_input(text):
|
| 4 |
+
if not text:
|
| 5 |
+
return "Please enter some text!"
|
| 6 |
+
|
| 7 |
+
output = f"""
|
| 8 |
+
You entered: {text}
|
| 9 |
+
Character count: {len(text)}
|
| 10 |
+
Word count: {len(text.split())}
|
| 11 |
+
"""
|
| 12 |
+
return output
|
| 13 |
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=process_input,
|
| 16 |
+
inputs=gr.Textbox(label="Enter your text", placeholder="Type something here..."),
|
| 17 |
+
outputs=gr.Textbox(label="Output"),
|
| 18 |
+
title="Simple Input/Output App",
|
| 19 |
+
description="Enter text and see character and word count"
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
gradio==4.0.0
|
ziko.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as py
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import gdown
|
| 6 |
+
|
| 7 |
+
# File IDs
|
| 8 |
+
model_id = "1HSQTjJ_hvBBmVJmYUmrkq5T7ubpfDwzF"
|
| 9 |
+
top_country_id = "1aLkaAqfrs3GcrMvZcuyQ0NjFhAhrdIlR"
|
| 10 |
+
|
| 11 |
+
model_url = f"https://drive.google.com/uc?id={model_id}"
|
| 12 |
+
top_country_url = f"https://drive.google.com/uc?id={top_country_id}"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@st.cache_resource
|
| 16 |
+
def load_model():
|
| 17 |
+
gdown.download(model_url, "best_rf_model.pkl", quiet=False)
|
| 18 |
+
with open("best_rf_model.pkl", "rb") as f:
|
| 19 |
+
return pickle.load(f)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@st.cache_resource
|
| 23 |
+
def load_top_country():
|
| 24 |
+
gdown.download(top_country_url, "top_country.pkl", quiet=False)
|
| 25 |
+
with open("top_country.pkl", "rb") as f:
|
| 26 |
+
return pickle.load(f)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
model = load_model()
|
| 30 |
+
top_country = load_top_country()
|
| 31 |
+
# Load
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def run():
|
| 35 |
+
with st.form(key="hotel_bookings"):
|
| 36 |
+
name = st.selectbox("Hotel Type", ("city_hotel", "resort_hotel"), index=0)
|
| 37 |
+
lead = st.number_input(
|
| 38 |
+
"Lead Time",
|
| 39 |
+
min_value=0,
|
| 40 |
+
max_value=600,
|
| 41 |
+
value=0,
|
| 42 |
+
step=1,
|
| 43 |
+
help="jarak antar waktu booking dan check-in",
|
| 44 |
+
)
|
| 45 |
+
arrival_year = st.selectbox("Arrival Year", ("2015", "2016", "2017"), index=0)
|
| 46 |
+
arrival_month = st.selectbox(
|
| 47 |
+
"Arrival Months",
|
| 48 |
+
(
|
| 49 |
+
"January",
|
| 50 |
+
"February",
|
| 51 |
+
"March",
|
| 52 |
+
"April",
|
| 53 |
+
"May",
|
| 54 |
+
"June",
|
| 55 |
+
"July",
|
| 56 |
+
"August",
|
| 57 |
+
"September",
|
| 58 |
+
"October",
|
| 59 |
+
"November",
|
| 60 |
+
"December",
|
| 61 |
+
),
|
| 62 |
+
index=0,
|
| 63 |
+
)
|
| 64 |
+
arrival_week = st.number_input(
|
| 65 |
+
"Arrival Weeks",
|
| 66 |
+
min_value=1,
|
| 67 |
+
max_value=52,
|
| 68 |
+
value=1,
|
| 69 |
+
step=1,
|
| 70 |
+
help="minggu kedatangan",
|
| 71 |
+
)
|
| 72 |
+
arrival_day = st.number_input(
|
| 73 |
+
"Arrival Days",
|
| 74 |
+
min_value=1,
|
| 75 |
+
max_value=31,
|
| 76 |
+
value=1,
|
| 77 |
+
step=1,
|
| 78 |
+
help="tanggal kedatangan",
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
submitted = st.form_submit_button("Predict")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == "_main_":
|
| 85 |
+
run()
|