Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import pandas as pd
|
| 4 |
import comtradeapicall
|
| 5 |
from huggingface_hub import InferenceClient
|
|
|
|
| 6 |
|
| 7 |
# کلید COMTRADE
|
| 8 |
subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
|
@@ -10,6 +11,7 @@ subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
|
| 10 |
hf_token = os.getenv("HF_API_TOKEN")
|
| 11 |
|
| 12 |
client = InferenceClient(token=hf_token)
|
|
|
|
| 13 |
|
| 14 |
def get_importers(hs_code: str, year: str, month: str):
|
| 15 |
period = f"{year}{int(month):02d}"
|
|
@@ -48,11 +50,16 @@ def provide_advice(table_data: pd.DataFrame, hs_code: str, year: str, month: str
|
|
| 48 |
outputs = client.text_generation(
|
| 49 |
prompt=prompt,
|
| 50 |
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 51 |
-
max_new_tokens=512
|
| 52 |
)
|
| 53 |
-
print("خروجی مدل دریافت
|
| 54 |
print(outputs)
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
error_msg = f"خطا در تولید مشاوره: {str(e)}"
|
| 58 |
print(error_msg)
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import comtradeapicall
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
+
from googletrans import Translator # اضافه کردن کتابخانه ترجمه
|
| 7 |
|
| 8 |
# کلید COMTRADE
|
| 9 |
subscription_key = os.getenv("COMTRADE_API_KEY", "")
|
|
|
|
| 11 |
hf_token = os.getenv("HF_API_TOKEN")
|
| 12 |
|
| 13 |
client = InferenceClient(token=hf_token)
|
| 14 |
+
translator = Translator() # ایجاد یک نمونه از مترجم
|
| 15 |
|
| 16 |
def get_importers(hs_code: str, year: str, month: str):
|
| 17 |
period = f"{year}{int(month):02d}"
|
|
|
|
| 50 |
outputs = client.text_generation(
|
| 51 |
prompt=prompt,
|
| 52 |
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 53 |
+
max_new_tokens=512
|
| 54 |
)
|
| 55 |
+
print("خروجی مدل دریافت شد (به انگلیسی):")
|
| 56 |
print(outputs)
|
| 57 |
+
|
| 58 |
+
# ترجمه خروجی به فارسی
|
| 59 |
+
translated_outputs = translator.translate(outputs, src='en', dest='fa').text
|
| 60 |
+
print("خروجی ترجمهشده به فارسی:")
|
| 61 |
+
print(translated_outputs)
|
| 62 |
+
return translated_outputs
|
| 63 |
except Exception as e:
|
| 64 |
error_msg = f"خطا در تولید مشاوره: {str(e)}"
|
| 65 |
print(error_msg)
|