Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import comtradeapicall
|
4 |
+
import os
|
5 |
+
|
6 |
+
# ۱) متغیرهای عمومی
|
7 |
+
subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
8 |
+
proxy_url = None
|
9 |
+
|
10 |
+
def get_importers(hs_code: str, period: str):
|
11 |
+
df = comtradeapicall.previewFinalData(
|
12 |
+
typeCode='C', freqCode='M', clCode='HS', period=period,
|
13 |
+
reporterCode=None, cmdCode=hs_code, flowCode='M',
|
14 |
+
partnerCode=None, partner2Code=None,
|
15 |
+
customsCode=None, motCode=None,
|
16 |
+
maxRecords=500, includeDesc=True,
|
17 |
+
proxy_url=proxy_url
|
18 |
+
)
|
19 |
+
if df is None or df.empty:
|
20 |
+
return "هیچ دادهای یافت نشد."
|
21 |
+
df = df[df['cifvalue'] > 0]
|
22 |
+
df = df.sort_values('cifvalue', ascending=False)
|
23 |
+
return df['reporterDesc'].tolist()
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("## جستوجوی واردکنندههای یک HS-Code")
|
27 |
+
with gr.Row():
|
28 |
+
inp_hs = gr.Textbox(label="HS Code (مثلا 010121)")
|
29 |
+
inp_period = gr.Textbox(label="دوره (YYYYMM، مثلاً 202205)")
|
30 |
+
btn = gr.Button("نمایش کشورها")
|
31 |
+
out = gr.Dataframe(headers=["کشورهای واردکننده"], interactive=False)
|
32 |
+
|
33 |
+
btn.click(fn=get_importers,
|
34 |
+
inputs=[inp_hs, inp_period],
|
35 |
+
outputs=out)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
demo.launch()
|