Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,10 +56,19 @@ def gen(prompt):
|
|
| 56 |
raise HTTPException(status_code=500, detail="AI Generation Failed")
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
@app.post("/vote")
|
| 60 |
-
async def vote(
|
| 61 |
-
data = {"id": unique_id, "vote": str(is_upvote)}
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return {"status": "success"}
|
| 64 |
|
| 65 |
|
|
|
|
| 56 |
raise HTTPException(status_code=500, detail="AI Generation Failed")
|
| 57 |
|
| 58 |
|
| 59 |
+
class VoteInput(BaseModel):
|
| 60 |
+
unique_id: str
|
| 61 |
+
is_upvote: bool
|
| 62 |
+
|
| 63 |
+
|
| 64 |
@app.post("/vote")
|
| 65 |
+
async def vote(vote_input: VoteInput):
|
| 66 |
+
data = {"id": vote_input.unique_id, "vote": str(vote_input.is_upvote)}
|
| 67 |
+
try:
|
| 68 |
+
response = requests.post(f"{Url}/vote", json=data, timeout=10)
|
| 69 |
+
response.raise_for_status()
|
| 70 |
+
except requests.RequestException as e:
|
| 71 |
+
raise HTTPException(status_code=502, detail=f"Failed to record vote: {str(e)}")
|
| 72 |
return {"status": "success"}
|
| 73 |
|
| 74 |
|