Spaces:
Runtime error
Runtime error
Commit
·
42a8ae5
1
Parent(s):
a8d8373
api
Browse files- backend/app.py +6 -2
- frontend/src/App.js +2 -2
backend/app.py
CHANGED
|
@@ -62,6 +62,8 @@ if os.path.exists(frontend_path):
|
|
| 62 |
else:
|
| 63 |
print(f"Warning: Frontend build directory '{frontend_path}' does not exist.")
|
| 64 |
|
|
|
|
|
|
|
| 65 |
def overlay_mask(base_image, mask_image, color_idx):
|
| 66 |
"""
|
| 67 |
Given the base_image and the 0/1 mask, overlay the mask with the color indexed by the color_idx.
|
|
@@ -150,7 +152,7 @@ async def return_state_data(state):
|
|
| 150 |
response['mask_overlayed_image'] = base64_str
|
| 151 |
return response
|
| 152 |
|
| 153 |
-
@
|
| 154 |
async def return_thumbnails_endpoint():
|
| 155 |
thumbnails = await return_thumbnails()
|
| 156 |
encoded_images = []
|
|
@@ -161,7 +163,7 @@ async def return_thumbnails_endpoint():
|
|
| 161 |
encoded_images.append(base64_str)
|
| 162 |
return JSONResponse(content={"thumbnails": encoded_images})
|
| 163 |
|
| 164 |
-
@
|
| 165 |
async def return_state_data_endpoint(
|
| 166 |
image_index: int = Query(...),
|
| 167 |
detail_level: int = Query(...),
|
|
@@ -181,6 +183,8 @@ async def return_state_data_endpoint(
|
|
| 181 |
response = await return_state_data(state)
|
| 182 |
return response
|
| 183 |
|
|
|
|
|
|
|
| 184 |
if __name__ == "__main__":
|
| 185 |
import uvicorn
|
| 186 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 62 |
else:
|
| 63 |
print(f"Warning: Frontend build directory '{frontend_path}' does not exist.")
|
| 64 |
|
| 65 |
+
api = FastAPI()
|
| 66 |
+
|
| 67 |
def overlay_mask(base_image, mask_image, color_idx):
|
| 68 |
"""
|
| 69 |
Given the base_image and the 0/1 mask, overlay the mask with the color indexed by the color_idx.
|
|
|
|
| 152 |
response['mask_overlayed_image'] = base64_str
|
| 153 |
return response
|
| 154 |
|
| 155 |
+
@api.get("/return_thumbnails")
|
| 156 |
async def return_thumbnails_endpoint():
|
| 157 |
thumbnails = await return_thumbnails()
|
| 158 |
encoded_images = []
|
|
|
|
| 163 |
encoded_images.append(base64_str)
|
| 164 |
return JSONResponse(content={"thumbnails": encoded_images})
|
| 165 |
|
| 166 |
+
@api.get("/return_state_data")
|
| 167 |
async def return_state_data_endpoint(
|
| 168 |
image_index: int = Query(...),
|
| 169 |
detail_level: int = Query(...),
|
|
|
|
| 183 |
response = await return_state_data(state)
|
| 184 |
return response
|
| 185 |
|
| 186 |
+
app.mount("/api", api)
|
| 187 |
+
|
| 188 |
if __name__ == "__main__":
|
| 189 |
import uvicorn
|
| 190 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
frontend/src/App.js
CHANGED
|
@@ -123,7 +123,7 @@ const App = () => {
|
|
| 123 |
useEffect(() => {
|
| 124 |
const fetchThumbnails = async () => {
|
| 125 |
try {
|
| 126 |
-
const response = await axios.get('/return_thumbnails');
|
| 127 |
const { thumbnails } = response.data;
|
| 128 |
setThumbnails(thumbnails.map((base64) => `data:image/png;base64,${base64}`)); // Decode Base64
|
| 129 |
} catch (error) {
|
|
@@ -144,7 +144,7 @@ const App = () => {
|
|
| 144 |
// join the valid indices with commas
|
| 145 |
const validIndicesStr = selectedValidIndices.length === 0 ? 'None' : selectedValidIndices.join(',');
|
| 146 |
|
| 147 |
-
const response = await axios.get('/return_state_data', {
|
| 148 |
params: {
|
| 149 |
image_index: selectedIdx,
|
| 150 |
detail_level: selectedDot,
|
|
|
|
| 123 |
useEffect(() => {
|
| 124 |
const fetchThumbnails = async () => {
|
| 125 |
try {
|
| 126 |
+
const response = await axios.get('/api/return_thumbnails');
|
| 127 |
const { thumbnails } = response.data;
|
| 128 |
setThumbnails(thumbnails.map((base64) => `data:image/png;base64,${base64}`)); // Decode Base64
|
| 129 |
} catch (error) {
|
|
|
|
| 144 |
// join the valid indices with commas
|
| 145 |
const validIndicesStr = selectedValidIndices.length === 0 ? 'None' : selectedValidIndices.join(',');
|
| 146 |
|
| 147 |
+
const response = await axios.get('/api/return_state_data', {
|
| 148 |
params: {
|
| 149 |
image_index: selectedIdx,
|
| 150 |
detail_level: selectedDot,
|