Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,39 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import shutil
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@app.post("/predict")
|
| 9 |
async def predict(request: Request):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
+
import uvicorn
|
| 3 |
|
| 4 |
+
app = FastAPI(title="Simple Uppercase API", description="Convert text to uppercase")
|
| 5 |
+
|
| 6 |
+
@app.get("/")
|
| 7 |
+
async def root():
|
| 8 |
+
return {"message": "Simple Uppercase API is running! Use POST /predict to convert text to uppercase."}
|
| 9 |
|
| 10 |
@app.post("/predict")
|
| 11 |
async def predict(request: Request):
|
| 12 |
+
try:
|
| 13 |
+
body = await request.json()
|
| 14 |
+
uid, question = body.get("data", [None, None])
|
| 15 |
+
|
| 16 |
+
# Check if we have valid input
|
| 17 |
+
if question is None:
|
| 18 |
+
return {
|
| 19 |
+
"error": "Invalid input format. Expected: {'data': ['uid', 'text_to_convert']}"
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Convert to uppercase
|
| 23 |
+
result = question.upper()
|
| 24 |
+
|
| 25 |
+
return {
|
| 26 |
+
"uid": uid,
|
| 27 |
+
"original_text": question,
|
| 28 |
+
"uppercase_text": result,
|
| 29 |
+
"status": "success"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return {
|
| 34 |
+
"error": f"Error processing request: {str(e)}",
|
| 35 |
+
"status": "error"
|
| 36 |
+
}
|
| 37 |
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
uvicorn.run(app, host="0.0.0.0", port=7860) # Port 7860 is standard for HF Spaces
|