Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import requests
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
@@ -27,8 +28,8 @@ async def generate_insight(request: Request):
|
|
| 27 |
Analyze the following compliance document status data and return a JSON with:
|
| 28 |
{{
|
| 29 |
"summary": "...",
|
| 30 |
-
"risks": [...],
|
| 31 |
-
"recommendations": [...]
|
| 32 |
}}
|
| 33 |
|
| 34 |
Data:
|
|
@@ -41,9 +42,9 @@ async def generate_insight(request: Request):
|
|
| 41 |
Analyze the resource usage data below. Return a JSON:
|
| 42 |
{{
|
| 43 |
"summary": "...",
|
| 44 |
-
"overutilized": [...],
|
| 45 |
-
"underutilized": [...],
|
| 46 |
-
"suggestions": [...]
|
| 47 |
}}
|
| 48 |
|
| 49 |
Data:
|
|
@@ -56,9 +57,39 @@ async def generate_insight(request: Request):
|
|
| 56 |
Analyze participant growth metrics and return JSON like:
|
| 57 |
{{
|
| 58 |
"summary": "...",
|
| 59 |
-
"trends": [...],
|
| 60 |
-
"risks": [...],
|
| 61 |
-
"recommendations": [...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}}
|
| 63 |
|
| 64 |
Data:
|
|
@@ -66,11 +97,11 @@ async def generate_insight(request: Request):
|
|
| 66 |
"""
|
| 67 |
else:
|
| 68 |
base_prompt = f"""
|
| 69 |
-
Analyze the following data and return
|
| 70 |
{{
|
| 71 |
"summary": "...",
|
| 72 |
-
"details": [...],
|
| 73 |
-
"recommendations": [...]
|
| 74 |
}}
|
| 75 |
|
| 76 |
Data:
|
|
@@ -85,8 +116,12 @@ async def generate_insight(request: Request):
|
|
| 85 |
|
| 86 |
try:
|
| 87 |
result = response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
return {
|
| 89 |
-
"
|
|
|
|
| 90 |
}
|
| 91 |
-
except Exception as e:
|
| 92 |
-
return {"error": "Gemini response format invalid", "details": str(response.json())}
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
|
|
| 28 |
Analyze the following compliance document status data and return a JSON with:
|
| 29 |
{{
|
| 30 |
"summary": "...",
|
| 31 |
+
"risks": ["..."],
|
| 32 |
+
"recommendations": ["..."]
|
| 33 |
}}
|
| 34 |
|
| 35 |
Data:
|
|
|
|
| 42 |
Analyze the resource usage data below. Return a JSON:
|
| 43 |
{{
|
| 44 |
"summary": "...",
|
| 45 |
+
"overutilized": ["..."],
|
| 46 |
+
"underutilized": ["..."],
|
| 47 |
+
"suggestions": ["..."]
|
| 48 |
}}
|
| 49 |
|
| 50 |
Data:
|
|
|
|
| 57 |
Analyze participant growth metrics and return JSON like:
|
| 58 |
{{
|
| 59 |
"summary": "...",
|
| 60 |
+
"trends": ["..."],
|
| 61 |
+
"risks": ["..."],
|
| 62 |
+
"recommendations": ["..."]
|
| 63 |
+
}}
|
| 64 |
+
|
| 65 |
+
Data:
|
| 66 |
+
{json.dumps(data, indent=2)}
|
| 67 |
+
"""
|
| 68 |
+
elif prompt_type == "intervention":
|
| 69 |
+
base_prompt = f"""
|
| 70 |
+
You are an incubation operations strategist.
|
| 71 |
+
|
| 72 |
+
Analyze intervention frequency, completion and category data. Return a JSON:
|
| 73 |
+
{{
|
| 74 |
+
"summary": "...",
|
| 75 |
+
"effective_areas": ["..."],
|
| 76 |
+
"gaps": ["..."],
|
| 77 |
+
"recommendations": ["..."]
|
| 78 |
+
}}
|
| 79 |
+
|
| 80 |
+
Data:
|
| 81 |
+
{json.dumps(data, indent=2)}
|
| 82 |
+
"""
|
| 83 |
+
elif prompt_type == "consultant":
|
| 84 |
+
base_prompt = f"""
|
| 85 |
+
You are evaluating consultant performance for an incubator program.
|
| 86 |
+
|
| 87 |
+
Using metrics like hours, rating, and impact scores, return JSON like:
|
| 88 |
+
{{
|
| 89 |
+
"summary": "...",
|
| 90 |
+
"top_performers": ["..."],
|
| 91 |
+
"underperformers": ["..."],
|
| 92 |
+
"recommendations": ["..."]
|
| 93 |
}}
|
| 94 |
|
| 95 |
Data:
|
|
|
|
| 97 |
"""
|
| 98 |
else:
|
| 99 |
base_prompt = f"""
|
| 100 |
+
Analyze the following data and return a useful JSON summary:
|
| 101 |
{{
|
| 102 |
"summary": "...",
|
| 103 |
+
"details": ["..."],
|
| 104 |
+
"recommendations": ["..."]
|
| 105 |
}}
|
| 106 |
|
| 107 |
Data:
|
|
|
|
| 116 |
|
| 117 |
try:
|
| 118 |
result = response.json()
|
| 119 |
+
insight_text = result["candidates"][0]["content"]["parts"][0]["text"]
|
| 120 |
+
return {
|
| 121 |
+
"insight": insight_text
|
| 122 |
+
}
|
| 123 |
+
except Exception:
|
| 124 |
return {
|
| 125 |
+
"error": "Gemini response format invalid",
|
| 126 |
+
"details": str(response.json())
|
| 127 |
}
|
|
|
|
|
|