Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,13 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import comtradeapicall
|
4 |
import os
|
|
|
5 |
|
6 |
subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
7 |
proxy_url = None
|
8 |
|
9 |
-
def get_importers(hs_code: str,
|
10 |
-
period = f"{
|
11 |
df = comtradeapicall.previewFinalData(
|
12 |
typeCode='C', freqCode='M', clCode='HS', period=period,
|
13 |
reporterCode=None, cmdCode=hs_code, flowCode='M',
|
@@ -27,18 +28,23 @@ def get_importers(hs_code: str, date):
|
|
27 |
result.columns = ["کد کشور","نام کشور","ارزش CIF"]
|
28 |
return result
|
29 |
|
|
|
|
|
|
|
|
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown("## نمایش کشورهایی که یک کالا را وارد کردهاند")
|
32 |
with gr.Row():
|
33 |
-
inp_hs
|
34 |
-
|
|
|
35 |
btn = gr.Button("نمایش اطلاعات")
|
36 |
out = gr.Dataframe(
|
37 |
headers=["کد کشور","نام کشور","ارزش CIF"],
|
38 |
datatype=["number","text","number"],
|
39 |
interactive=False
|
40 |
)
|
41 |
-
btn.click(get_importers, [inp_hs,
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
demo.launch()
|
|
|
2 |
import pandas as pd
|
3 |
import comtradeapicall
|
4 |
import os
|
5 |
+
from datetime import datetime
|
6 |
|
7 |
subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
8 |
proxy_url = None
|
9 |
|
10 |
+
def get_importers(hs_code: str, year: str, month: str):
|
11 |
+
period = f"{year}{int(month):02d}"
|
12 |
df = comtradeapicall.previewFinalData(
|
13 |
typeCode='C', freqCode='M', clCode='HS', period=period,
|
14 |
reporterCode=None, cmdCode=hs_code, flowCode='M',
|
|
|
28 |
result.columns = ["کد کشور","نام کشور","ارزش CIF"]
|
29 |
return result
|
30 |
|
31 |
+
current_year = datetime.now().year
|
32 |
+
years = [str(y) for y in range(2000, current_year+1)]
|
33 |
+
months = [str(m) for m in range(1, 13)]
|
34 |
+
|
35 |
with gr.Blocks() as demo:
|
36 |
gr.Markdown("## نمایش کشورهایی که یک کالا را وارد کردهاند")
|
37 |
with gr.Row():
|
38 |
+
inp_hs = gr.Textbox(label="HS Code")
|
39 |
+
inp_year = gr.Dropdown(choices=years, label="سال", value=str(current_year))
|
40 |
+
inp_month = gr.Dropdown(choices=months, label="ماه", value=str(datetime.now().month))
|
41 |
btn = gr.Button("نمایش اطلاعات")
|
42 |
out = gr.Dataframe(
|
43 |
headers=["کد کشور","نام کشور","ارزش CIF"],
|
44 |
datatype=["number","text","number"],
|
45 |
interactive=False
|
46 |
)
|
47 |
+
btn.click(get_importers, inputs=[inp_hs, inp_year, inp_month], outputs=out)
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
demo.launch()
|