Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
-
from fastapi.responses import StreamingResponse
|
|
|
|
| 3 |
import aiohttp
|
| 4 |
import json
|
| 5 |
import time
|
|
|
|
| 6 |
import ast
|
|
|
|
| 7 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 8 |
import os
|
| 9 |
from pydantic import BaseModel
|
|
@@ -64,6 +67,7 @@ async def stream_text(request: StreamTextRequest):
|
|
| 64 |
|
| 65 |
api_key = request.api_key if request.api_key != 'none' else SAMBA_NOVA_API_KEY
|
| 66 |
|
|
|
|
| 67 |
async def stream_response():
|
| 68 |
async with aiohttp.ClientSession() as session:
|
| 69 |
async with session.post('https://api.sambanova.ai/v1/chat/completions', headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' }, json=data) as response:
|
|
@@ -92,7 +96,10 @@ async def stream_text(request: StreamTextRequest):
|
|
| 92 |
return StreamingResponse(stream_response(), media_type='text/event-stream')
|
| 93 |
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
@app.get("/script1.js")
|
| 97 |
async def script1_js():
|
| 98 |
return FileResponse("script1.js")
|
|
@@ -105,10 +112,10 @@ async def script2_js():
|
|
| 105 |
async def styles_css():
|
| 106 |
return FileResponse("styles.css")
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
import uvicorn
|
| 114 |
-
uvicorn.run(app, host="0.0.0.0", port=7068, reload=True)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
+
from fastapi.responses import StreamingResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
import aiohttp
|
| 5 |
import json
|
| 6 |
import time
|
| 7 |
+
import random
|
| 8 |
import ast
|
| 9 |
+
import urllib.parse
|
| 10 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 11 |
import os
|
| 12 |
from pydantic import BaseModel
|
|
|
|
| 67 |
|
| 68 |
api_key = request.api_key if request.api_key != 'none' else SAMBA_NOVA_API_KEY
|
| 69 |
|
| 70 |
+
|
| 71 |
async def stream_response():
|
| 72 |
async with aiohttp.ClientSession() as session:
|
| 73 |
async with session.post('https://api.sambanova.ai/v1/chat/completions', headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' }, json=data) as response:
|
|
|
|
| 96 |
return StreamingResponse(stream_response(), media_type='text/event-stream')
|
| 97 |
|
| 98 |
|
| 99 |
+
|
| 100 |
+
# Serve index.html from the same directory as your main.py file
|
| 101 |
+
from starlette.responses import FileResponse
|
| 102 |
+
|
| 103 |
@app.get("/script1.js")
|
| 104 |
async def script1_js():
|
| 105 |
return FileResponse("script1.js")
|
|
|
|
| 112 |
async def styles_css():
|
| 113 |
return FileResponse("styles.css")
|
| 114 |
|
| 115 |
+
@app.get("/")
|
| 116 |
+
async def read_index():
|
| 117 |
+
return FileResponse('index.html')
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
| 120 |
import uvicorn
|
| 121 |
+
uvicorn.run(app, host="0.0.0.0", port=7068, reload=True)
|