Spaces:
Sleeping
Sleeping
Commit ·
e483a33
1
Parent(s): e937e73
commit 00000004
Browse files- app.py +12 -4
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -9,6 +9,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 9 |
from huggingface_hub import login
|
| 10 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 11 |
import re
|
|
|
|
|
|
|
| 12 |
from gradio.routes import mount_gradio_app
|
| 13 |
|
| 14 |
# ✅ Safe GPU decorator
|
|
@@ -178,8 +180,14 @@ with gr.Blocks() as demo:
|
|
| 178 |
|
| 179 |
# # Start Flask in a background thread
|
| 180 |
# threading.Thread(target=run_flask, daemon=True).start()
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
# Gradio runs on port 7860 in HF Spaces
|
| 184 |
-
if __name__ == "__main__":
|
| 185 |
-
|
|
|
|
| 9 |
from huggingface_hub import login
|
| 10 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 11 |
import re
|
| 12 |
+
from fastapi import FastAPI
|
| 13 |
+
from starlette.middleware.wsgi import WSGIMiddleware
|
| 14 |
from gradio.routes import mount_gradio_app
|
| 15 |
|
| 16 |
# ✅ Safe GPU decorator
|
|
|
|
| 180 |
|
| 181 |
# # Start Flask in a background thread
|
| 182 |
# threading.Thread(target=run_flask, daemon=True).start()
|
| 183 |
+
# ---------------- Combine Flask + Gradio into one app ----------------
|
| 184 |
+
fastapi_app = FastAPI()
|
| 185 |
+
|
| 186 |
+
# Mount Flask under FastAPI (so /apidocs works)
|
| 187 |
+
fastapi_app.mount("/", WSGIMiddleware(flask_app))
|
| 188 |
+
|
| 189 |
+
# Mount Gradio at root path (overrides Flask's "/")
|
| 190 |
+
app = mount_gradio_app(fastapi_app, demo, path="/") # Mount Flask under /flask
|
| 191 |
# Gradio runs on port 7860 in HF Spaces
|
| 192 |
+
# if __name__ == "__main__":
|
| 193 |
+
# demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -14,4 +14,6 @@ sentencepiece
|
|
| 14 |
nltk
|
| 15 |
langchain_community
|
| 16 |
duckduckgo-search
|
| 17 |
-
pdfplumber
|
|
|
|
|
|
|
|
|
| 14 |
nltk
|
| 15 |
langchain_community
|
| 16 |
duckduckgo-search
|
| 17 |
+
pdfplumber
|
| 18 |
+
fastapi
|
| 19 |
+
uvicorn
|