Spaces:
Sleeping
Sleeping
updated
Browse files- app.py +7 -3
- static/index.html +2 -2
app.py
CHANGED
|
@@ -62,7 +62,7 @@ Answer:"""
|
|
| 62 |
raise ValueError(f"Error saving embeddings: {str(e)}")
|
| 63 |
|
| 64 |
|
| 65 |
-
api_key = "
|
| 66 |
chat_app = GroqAIChatApp(api_key=api_key)
|
| 67 |
|
| 68 |
app = FastAPI()
|
|
@@ -80,7 +80,7 @@ async def serve_frontend():
|
|
| 80 |
with open("static/index.html", "r") as file:
|
| 81 |
return HTMLResponse(content=file.read())
|
| 82 |
|
| 83 |
-
@app.post("/qa")
|
| 84 |
async def qa_endpoint(request: Request):
|
| 85 |
try:
|
| 86 |
data = await request.json()
|
|
@@ -93,7 +93,7 @@ async def qa_endpoint(request: Request):
|
|
| 93 |
except Exception as e:
|
| 94 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 95 |
|
| 96 |
-
@app.post("/upload")
|
| 97 |
async def upload_file(file: UploadFile = File(...)):
|
| 98 |
try:
|
| 99 |
text = chat_app.process_file(file)
|
|
@@ -105,3 +105,7 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 105 |
|
| 106 |
current_dir = Path(__file__).parent
|
| 107 |
app.mount("/static", StaticFiles(directory=current_dir / "static"), name="static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
raise ValueError(f"Error saving embeddings: {str(e)}")
|
| 63 |
|
| 64 |
|
| 65 |
+
api_key = "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" # Replace with your Groq API key
|
| 66 |
chat_app = GroqAIChatApp(api_key=api_key)
|
| 67 |
|
| 68 |
app = FastAPI()
|
|
|
|
| 80 |
with open("static/index.html", "r") as file:
|
| 81 |
return HTMLResponse(content=file.read())
|
| 82 |
|
| 83 |
+
@app.post("/api/qa")
|
| 84 |
async def qa_endpoint(request: Request):
|
| 85 |
try:
|
| 86 |
data = await request.json()
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
return JSONResponse({"error": str(e)}, status_code=500)
|
| 95 |
|
| 96 |
+
@app.post("/api/upload")
|
| 97 |
async def upload_file(file: UploadFile = File(...)):
|
| 98 |
try:
|
| 99 |
text = chat_app.process_file(file)
|
|
|
|
| 105 |
|
| 106 |
current_dir = Path(__file__).parent
|
| 107 |
app.mount("/static", StaticFiles(directory=current_dir / "static"), name="static")
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
import uvicorn
|
| 111 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
static/index.html
CHANGED
|
@@ -195,7 +195,7 @@
|
|
| 195 |
questionInput.value = '';
|
| 196 |
|
| 197 |
try {
|
| 198 |
-
const response = await fetch('
|
| 199 |
method: 'POST',
|
| 200 |
headers: { 'Content-Type': 'application/json' },
|
| 201 |
body: JSON.stringify({ question }),
|
|
@@ -222,7 +222,7 @@
|
|
| 222 |
});
|
| 223 |
|
| 224 |
try {
|
| 225 |
-
const response = await fetch('
|
| 226 |
method: 'POST',
|
| 227 |
body: formData,
|
| 228 |
});
|
|
|
|
| 195 |
questionInput.value = '';
|
| 196 |
|
| 197 |
try {
|
| 198 |
+
const response = await fetch('/api/qa', {
|
| 199 |
method: 'POST',
|
| 200 |
headers: { 'Content-Type': 'application/json' },
|
| 201 |
body: JSON.stringify({ question }),
|
|
|
|
| 222 |
});
|
| 223 |
|
| 224 |
try {
|
| 225 |
+
const response = await fetch('/api/upload', {
|
| 226 |
method: 'POST',
|
| 227 |
body: formData,
|
| 228 |
});
|