Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,14 +6,30 @@ import os
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
# بارگیری مدل و توکنایزر
|
| 9 |
-
model_name = "
|
| 10 |
hf_token = os.getenv("HUGGINGFACE_TOKEN") # خواندن توکن از متغیر محیطی
|
| 11 |
|
| 12 |
if hf_token is None:
|
| 13 |
raise ValueError("HUGGINGFACE_TOKEN environment variable is not set.")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
@app.get("/generate")
|
| 19 |
async def generate_text(prompt: str = Query(..., description="متن ورودی برای تولید متن")):
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
# بارگیری مدل و توکنایزر
|
| 9 |
+
model_name = "moonshotai/Kimi-VL-A3B-Thinking"
|
| 10 |
hf_token = os.getenv("HUGGINGFACE_TOKEN") # خواندن توکن از متغیر محیطی
|
| 11 |
|
| 12 |
if hf_token is None:
|
| 13 |
raise ValueError("HUGGINGFACE_TOKEN environment variable is not set.")
|
| 14 |
|
| 15 |
+
# بررسی بارگیری مدل
|
| 16 |
+
try:
|
| 17 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
|
| 18 |
+
print("Model loaded successfully.")
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Error loading model: {e}")
|
| 21 |
+
raise
|
| 22 |
+
|
| 23 |
+
# بررسی توکنایزر
|
| 24 |
+
try:
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
|
| 26 |
+
test_text = "This is a test."
|
| 27 |
+
tokens = tokenizer(test_text, return_tensors="pt")
|
| 28 |
+
print("Tokenizer works successfully.")
|
| 29 |
+
print(tokens)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Error with tokenizer: {e}")
|
| 32 |
+
raise
|
| 33 |
|
| 34 |
@app.get("/generate")
|
| 35 |
async def generate_text(prompt: str = Query(..., description="متن ورودی برای تولید متن")):
|