Spaces:
Runtime error
Runtime error
Saqib commited on
Update modules/app.py
Browse files119 unmodified lines12012112212312412512612712812913013113213313413513613713813914014114214314414514614714829 unmodified lines178179180181182183184185186187188189190191192193194195196197198199200119 unmodified linesif not image_url:raise HTTPException(status_code=400, detail="image_url not found in request")def extract_coordinates(text):# Split the text into lineslines = text.split('\n')# Iterate through each line to find the one that contains the coordinatesfor line in lines:try:if line.startswith("Coordinates:"):# Remove the label and split by commacoords = line.replace("Coordinates:", "").strip()lat, lon = coords.split(',')# Further split by space to isolate numerical valueslatitude = float(lat.split('°')[0].strip())longitude = float(lon.split('°')[0].strip())return latitude, longitudeexcept Exception as e:print("Error:", e)return None# Return None if no coordinates are foundreturn Noneheaders = {'accept': '*/*',29 unmodified linesif response.status != 200:return f"Failed to upload image: HTTP {response.status}"json_response = await response.json()if 'message' in json_response:json_response['message'] = json_response['message'].strip()coordinates = extract_coordinates(json_response['message'])if coordinates:latitude, longitude = coordinatesgoogle_maps = f"https://www.google.com/maps/search/?api=1&query={latitude},{longitude}"json_response['message'] += f"\n\nView on Google Maps: {google_maps}"if img2location_name in json_response['message'].lower():raise HTTPException(status_code=400, detail="We are not allowed to process this image. Please try another one.")return json_responseraise ValueError(f"Unexpected response: {json_response}")@app.post("/pixart-sigma")async def pixart_sigma(request: Request):119 unmodified lines12012112212312412529 unmodified lines155156157158159160161119 unmodified linesif not image_url:raise HTTPException(status_code=400, detail="image_url not found in request")headers = {'accept': '*/*',29 unmodified linesif response.status != 200:return f"Failed to upload image: HTTP {response.status}"json_response = await response.json()return json_response@app.post("/pixart-sigma")async def pixart_sigma(request: Request):
modules/app.py+1-40