Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,14 @@ from fastapi import FastAPI, HTTPException
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from typing import Dict, List
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
import numpy as np
|
| 7 |
-
from transformers import RobertaTokenizer
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
import uvicorn
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
os.environ["
|
| 13 |
|
| 14 |
# Initialize FastAPI app
|
| 15 |
app = FastAPI(
|
|
@@ -56,8 +56,10 @@ def load_model():
|
|
| 56 |
cache_dir=None # Use default cache
|
| 57 |
)
|
| 58 |
print(f"Model downloaded to: {model_path}")
|
| 59 |
-
# Load the model
|
| 60 |
-
model
|
|
|
|
|
|
|
| 61 |
return model
|
| 62 |
except Exception as e:
|
| 63 |
raise RuntimeError(f"Error loading model: {str(e)}")
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from typing import Dict, List
|
| 4 |
import os
|
| 5 |
+
import tensorflow as tf
|
| 6 |
import numpy as np
|
| 7 |
+
from transformers import RobertaTokenizer, TFRobertaModel
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
import uvicorn
|
| 10 |
|
| 11 |
+
# Ensure TensorFlow uses its own Keras
|
| 12 |
+
os.environ["TF_USE_LEGACY_KERAS"] = "1"
|
| 13 |
|
| 14 |
# Initialize FastAPI app
|
| 15 |
app = FastAPI(
|
|
|
|
| 56 |
cache_dir=None # Use default cache
|
| 57 |
)
|
| 58 |
print(f"Model downloaded to: {model_path}")
|
| 59 |
+
# Load the model using TensorFlow's Keras (not standalone Keras)
|
| 60 |
+
# This is needed because the model was saved with tf_keras
|
| 61 |
+
model = tf.keras.models.load_model(model_path, compile=False)
|
| 62 |
+
print("Model loaded successfully!")
|
| 63 |
return model
|
| 64 |
except Exception as e:
|
| 65 |
raise RuntimeError(f"Error loading model: {str(e)}")
|