Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,9 @@ from PIL import Image
|
|
| 10 |
import time
|
| 11 |
from datetime import datetime
|
| 12 |
import os
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Google Drive imports
|
| 15 |
from google.oauth2 import service_account
|
|
@@ -193,6 +196,33 @@ def save_to_google_drive(image, prompt):
|
|
| 193 |
traceback.print_exc()
|
| 194 |
return None
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
# Request model
|
| 197 |
class GenerateRequest(BaseModel):
|
| 198 |
prompt: str
|
|
|
|
| 10 |
import time
|
| 11 |
from datetime import datetime
|
| 12 |
import os
|
| 13 |
+
from fastapi import Request
|
| 14 |
+
from fastapi.responses import HTMLResponse
|
| 15 |
+
|
| 16 |
|
| 17 |
# Google Drive imports
|
| 18 |
from google.oauth2 import service_account
|
|
|
|
| 196 |
traceback.print_exc()
|
| 197 |
return None
|
| 198 |
|
| 199 |
+
# Add this simple OAuth callback handler
|
| 200 |
+
@app.get("/oauth2callback", response_class=HTMLResponse)
|
| 201 |
+
async def oauth2_callback(request: Request):
|
| 202 |
+
"""
|
| 203 |
+
Simple endpoint to handle OAuth2 redirect and display the authorization code
|
| 204 |
+
"""
|
| 205 |
+
code = request.query_params.get("code")
|
| 206 |
+
if code:
|
| 207 |
+
# Display the code in a simple HTML page
|
| 208 |
+
html_content = f"""
|
| 209 |
+
<html>
|
| 210 |
+
<head><title>Authentication Successful</title></head>
|
| 211 |
+
<body>
|
| 212 |
+
<h2>✅ Authentication Successful!</h2>
|
| 213 |
+
<p>Your authorization code has been received.</p>
|
| 214 |
+
<p>Please copy this code and paste it back into Termux:</p>
|
| 215 |
+
<div style="background: #f0f0f0; padding: 10px; border-radius: 5px; word-break: break-all;">
|
| 216 |
+
<strong>{code}</strong>
|
| 217 |
+
</div>
|
| 218 |
+
<p><br>Then press Enter to complete the process.</p>
|
| 219 |
+
</body>
|
| 220 |
+
</html>
|
| 221 |
+
"""
|
| 222 |
+
return HTMLResponse(content=html_content)
|
| 223 |
+
else:
|
| 224 |
+
return HTMLResponse(content="<h2>❌ No authorization code received</h2>")
|
| 225 |
+
|
| 226 |
# Request model
|
| 227 |
class GenerateRequest(BaseModel):
|
| 228 |
prompt: str
|