Sam Fred
commited on
Commit
·
6bc84bd
1
Parent(s):
628d522
commit
Browse files- app.py +8 -18
- scripts/train_engagement_rate.py +2 -1
- scripts/train_promotion_strategy.py +2 -1
- scripts/train_time_series.py +2 -1
- scripts/train_viral_potential.py +2 -1
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from utils.logging_utils import setup_logging
|
| 3 |
from scripts.train_viral_potential import train_viral_potential
|
| 4 |
from scripts.train_engagement_rate import train_engagement_rate
|
|
@@ -10,27 +9,18 @@ from scripts.analyze_engagement import analyze_engagement
|
|
| 10 |
# Set up logging
|
| 11 |
setup_logging()
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
@app.get("/")
|
| 17 |
-
def read_root():
|
| 18 |
-
return {"message": "Instagram AI Backend"}
|
| 19 |
-
|
| 20 |
-
@app.post("/train-models")
|
| 21 |
-
def train_models():
|
| 22 |
train_viral_potential()
|
| 23 |
train_engagement_rate()
|
| 24 |
train_promotion_strategy()
|
| 25 |
train_time_series()
|
| 26 |
-
return {"message": "Models trained successfully"}
|
| 27 |
|
| 28 |
-
|
| 29 |
-
def analyze_engagement_endpoint():
|
| 30 |
analyze_engagement()
|
| 31 |
-
return {"message": "Engagement analysis completed"}
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 1 |
from utils.logging_utils import setup_logging
|
| 2 |
from scripts.train_viral_potential import train_viral_potential
|
| 3 |
from scripts.train_engagement_rate import train_engagement_rate
|
|
|
|
| 9 |
# Set up logging
|
| 10 |
setup_logging()
|
| 11 |
|
| 12 |
+
# Main application logic
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
# Train and export models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
train_viral_potential()
|
| 16 |
train_engagement_rate()
|
| 17 |
train_promotion_strategy()
|
| 18 |
train_time_series()
|
|
|
|
| 19 |
|
| 20 |
+
# Analyze engagement data
|
|
|
|
| 21 |
analyze_engagement()
|
|
|
|
| 22 |
|
| 23 |
+
# Analyze an example image
|
| 24 |
+
image_url = "https://example.com/path/to/image.jpg"
|
| 25 |
+
caption = "This is a beautiful sunset!"
|
| 26 |
+
analyze_image_url(image_url, caption)
|
scripts/train_engagement_rate.py
CHANGED
|
@@ -23,4 +23,5 @@ def train_engagement_rate():
|
|
| 23 |
print(f"Engagement Rate Prediction Model - MAE: {mae:.4f}")
|
| 24 |
|
| 25 |
# Save the model
|
| 26 |
-
joblib.dump(engagement_model, "models/engagement_rate_model.pkl")
|
|
|
|
|
|
| 23 |
print(f"Engagement Rate Prediction Model - MAE: {mae:.4f}")
|
| 24 |
|
| 25 |
# Save the model
|
| 26 |
+
joblib.dump(engagement_model, "models/engagement_rate_model.pkl")
|
| 27 |
+
print("Engagement Rate Model saved to models/engagement_rate_model.pkl")
|
scripts/train_promotion_strategy.py
CHANGED
|
@@ -26,4 +26,5 @@ def train_promotion_strategy():
|
|
| 26 |
print(f"Promotion Prediction Model Accuracy: {accuracy:.4f}")
|
| 27 |
|
| 28 |
# Save the model
|
| 29 |
-
joblib.dump(promotion_model, "models/promotion_strategy_model.pkl")
|
|
|
|
|
|
| 26 |
print(f"Promotion Prediction Model Accuracy: {accuracy:.4f}")
|
| 27 |
|
| 28 |
# Save the model
|
| 29 |
+
joblib.dump(promotion_model, "models/promotion_strategy_model.pkl")
|
| 30 |
+
print("Promotion Strategy Model saved to models/promotion_strategy_model.pkl")
|
scripts/train_time_series.py
CHANGED
|
@@ -19,4 +19,5 @@ def train_time_series():
|
|
| 19 |
prophet_model.fit(time_series_data)
|
| 20 |
|
| 21 |
# Save the model
|
| 22 |
-
joblib.dump(prophet_model, "models/prophet_model.pkl")
|
|
|
|
|
|
| 19 |
prophet_model.fit(time_series_data)
|
| 20 |
|
| 21 |
# Save the model
|
| 22 |
+
joblib.dump(prophet_model, "models/prophet_model.pkl")
|
| 23 |
+
print("Prophet Model saved to models/prophet_model.pkl")
|
scripts/train_viral_potential.py
CHANGED
|
@@ -26,4 +26,5 @@ def train_viral_potential():
|
|
| 26 |
print(f"Viral Potential Model Accuracy: {accuracy:.4f}")
|
| 27 |
|
| 28 |
# Save the model
|
| 29 |
-
joblib.dump(viral_model, "models/viral_potential_model.pkl")
|
|
|
|
|
|
| 26 |
print(f"Viral Potential Model Accuracy: {accuracy:.4f}")
|
| 27 |
|
| 28 |
# Save the model
|
| 29 |
+
joblib.dump(viral_model, "models/viral_potential_model.pkl")
|
| 30 |
+
print("Viral Potential Model saved to models/viral_potential_model.pkl")
|