Commit
·
02aef91
1
Parent(s):
6dddef0
feat(earnings): Add unique commentary for all content formats
Browse files- api/main.py +17 -18
api/main.py
CHANGED
|
@@ -995,33 +995,29 @@ Task Title: "{request.title}"
|
|
| 995 |
@app.post("/predict/earning-opportunities", response_model=EarningOpportunityResponse, summary="Finds the best earning opportunities for an influencer")
|
| 996 |
async def predict_earning_opportunities(request: EarningOpportunityRequest):
|
| 997 |
"""
|
| 998 |
-
[
|
| 999 |
-
|
| 1000 |
"""
|
| 1001 |
-
print(f"\n✅ Received request on /predict/earning-opportunities (
|
| 1002 |
if _earnings_optimizer is None or _earnings_encoder is None:
|
| 1003 |
raise HTTPException(status_code=503, detail="Earning Optimizer model or encoder is not available.")
|
| 1004 |
|
| 1005 |
try:
|
|
|
|
| 1006 |
scenarios_list = [
|
| 1007 |
{'campaign_niche': niche, 'content_format': c_format, 'follower_count': request.follower_count}
|
| 1008 |
for niche in ['Tech', 'Fashion', 'Food', 'Gaming', 'General']
|
| 1009 |
for c_format in ['Reel', 'Post', 'Story']
|
| 1010 |
]
|
| 1011 |
df_scenarios = pd.DataFrame(scenarios_list)
|
| 1012 |
-
|
| 1013 |
-
print(" - Manually encoding data using saved encoder...")
|
| 1014 |
categorical_features = ['campaign_niche', 'content_format']
|
| 1015 |
encoded_cats = _earnings_encoder.transform(df_scenarios[categorical_features])
|
| 1016 |
encoded_df = pd.DataFrame(encoded_cats, columns=_earnings_encoder.get_feature_names_out(categorical_features))
|
| 1017 |
-
|
| 1018 |
numerical_features = df_scenarios[['follower_count']].reset_index(drop=True)
|
| 1019 |
X_final_to_predict = pd.concat([encoded_df, numerical_features], axis=1)
|
| 1020 |
-
|
| 1021 |
-
print(f" - Predicting scores for {len(X_final_to_predict)} scenarios...")
|
| 1022 |
predicted_scores = _earnings_optimizer.predict(X_final_to_predict)
|
| 1023 |
|
| 1024 |
-
# === ✨
|
| 1025 |
results = []
|
| 1026 |
for i, scenario in enumerate(scenarios_list):
|
| 1027 |
score = float(predicted_scores[i])
|
|
@@ -1030,19 +1026,21 @@ async def predict_earning_opportunities(request: EarningOpportunityRequest):
|
|
| 1030 |
|
| 1031 |
# Default commentary based on score
|
| 1032 |
if score > 0.75:
|
| 1033 |
-
comment = "
|
| 1034 |
elif score < 0.4:
|
| 1035 |
-
comment = "This
|
| 1036 |
else:
|
| 1037 |
comment = "This is a solid opportunity worth exploring."
|
| 1038 |
|
| 1039 |
-
# Add dynamic, helpful tips
|
| 1040 |
if c_format == 'Reel':
|
| 1041 |
-
comment += " Reels are
|
| 1042 |
-
elif c_format == 'Post'
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
|
|
|
|
|
|
| 1046 |
|
| 1047 |
results.append(Opportunity(
|
| 1048 |
campaign_niche=niche,
|
|
@@ -1050,7 +1048,7 @@ async def predict_earning_opportunities(request: EarningOpportunityRequest):
|
|
| 1050 |
estimated_score=score,
|
| 1051 |
commentary=comment
|
| 1052 |
))
|
| 1053 |
-
# === ✨ END OF
|
| 1054 |
|
| 1055 |
sorted_results = sorted(results, key=lambda x: x.estimated_score, reverse=True)
|
| 1056 |
return EarningOpportunityResponse(opportunities=sorted_results[:5])
|
|
@@ -1059,6 +1057,7 @@ async def predict_earning_opportunities(request: EarningOpportunityRequest):
|
|
| 1059 |
print("🚨 An error occurred in /predict/earning-opportunities endpoint:")
|
| 1060 |
traceback.print_exc()
|
| 1061 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 1062 |
|
| 1063 |
@app.post("/predict/post-performance", response_model=PostPerformanceResponse, summary="Predicts likes and comments for a new post")
|
| 1064 |
async def predict_post_performance(request: PostPerformanceRequest):
|
|
|
|
| 995 |
@app.post("/predict/earning-opportunities", response_model=EarningOpportunityResponse, summary="Finds the best earning opportunities for an influencer")
|
| 996 |
async def predict_earning_opportunities(request: EarningOpportunityRequest):
|
| 997 |
"""
|
| 998 |
+
[FINAL POLISHED VERSION] Uses the model for a score and adds dynamic, helpful
|
| 999 |
+
commentary for every content format.
|
| 1000 |
"""
|
| 1001 |
+
print(f"\n✅ Received request on /predict/earning-opportunities (FINAL POLISH)")
|
| 1002 |
if _earnings_optimizer is None or _earnings_encoder is None:
|
| 1003 |
raise HTTPException(status_code=503, detail="Earning Optimizer model or encoder is not available.")
|
| 1004 |
|
| 1005 |
try:
|
| 1006 |
+
# This part remains the same: preparing data and getting a score from the model
|
| 1007 |
scenarios_list = [
|
| 1008 |
{'campaign_niche': niche, 'content_format': c_format, 'follower_count': request.follower_count}
|
| 1009 |
for niche in ['Tech', 'Fashion', 'Food', 'Gaming', 'General']
|
| 1010 |
for c_format in ['Reel', 'Post', 'Story']
|
| 1011 |
]
|
| 1012 |
df_scenarios = pd.DataFrame(scenarios_list)
|
|
|
|
|
|
|
| 1013 |
categorical_features = ['campaign_niche', 'content_format']
|
| 1014 |
encoded_cats = _earnings_encoder.transform(df_scenarios[categorical_features])
|
| 1015 |
encoded_df = pd.DataFrame(encoded_cats, columns=_earnings_encoder.get_feature_names_out(categorical_features))
|
|
|
|
| 1016 |
numerical_features = df_scenarios[['follower_count']].reset_index(drop=True)
|
| 1017 |
X_final_to_predict = pd.concat([encoded_df, numerical_features], axis=1)
|
|
|
|
|
|
|
| 1018 |
predicted_scores = _earnings_optimizer.predict(X_final_to_predict)
|
| 1019 |
|
| 1020 |
+
# === ✨ FINAL POLISH: MORE DYNAMIC COMMENTARY LOGIC ✨ ===
|
| 1021 |
results = []
|
| 1022 |
for i, scenario in enumerate(scenarios_list):
|
| 1023 |
score = float(predicted_scores[i])
|
|
|
|
| 1026 |
|
| 1027 |
# Default commentary based on score
|
| 1028 |
if score > 0.75:
|
| 1029 |
+
comment = "Excellent match! This area has high potential for you."
|
| 1030 |
elif score < 0.4:
|
| 1031 |
+
comment = "This could be a challenging area to grow in."
|
| 1032 |
else:
|
| 1033 |
comment = "This is a solid opportunity worth exploring."
|
| 1034 |
|
| 1035 |
+
# Add dynamic, helpful tips for EVERY format
|
| 1036 |
if c_format == 'Reel':
|
| 1037 |
+
comment += " Reels are perfect for reaching a wider audience with trending audio."
|
| 1038 |
+
elif c_format == 'Post':
|
| 1039 |
+
# Ab yeh tip hamesha 'Post' ke saath aayegi
|
| 1040 |
+
comment += " Use high-quality visuals and a strong caption for best results with posts."
|
| 1041 |
+
elif c_format == 'Story':
|
| 1042 |
+
# Ab yeh tip hamesha 'Story' ke saath aayegi
|
| 1043 |
+
comment += " Stories are great for engaging your current followers with interactive polls or Q&As."
|
| 1044 |
|
| 1045 |
results.append(Opportunity(
|
| 1046 |
campaign_niche=niche,
|
|
|
|
| 1048 |
estimated_score=score,
|
| 1049 |
commentary=comment
|
| 1050 |
))
|
| 1051 |
+
# === ✨ END OF FINAL POLISH ✨ ===
|
| 1052 |
|
| 1053 |
sorted_results = sorted(results, key=lambda x: x.estimated_score, reverse=True)
|
| 1054 |
return EarningOpportunityResponse(opportunities=sorted_results[:5])
|
|
|
|
| 1057 |
print("🚨 An error occurred in /predict/earning-opportunities endpoint:")
|
| 1058 |
traceback.print_exc()
|
| 1059 |
raise HTTPException(status_code=500, detail=str(e))
|
| 1060 |
+
|
| 1061 |
|
| 1062 |
@app.post("/predict/post-performance", response_model=PostPerformanceResponse, summary="Predicts likes and comments for a new post")
|
| 1063 |
async def predict_post_performance(request: PostPerformanceRequest):
|