Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import faiss
|
|
7 |
import numpy as np
|
8 |
from sentence_transformers import SentenceTransformer
|
9 |
import requests
|
|
|
|
|
10 |
|
11 |
# β
Load RAG-related files
|
12 |
with open("texts.json", "r", encoding="utf-8") as f:
|
@@ -15,7 +17,6 @@ with open("texts.json", "r", encoding="utf-8") as f:
|
|
15 |
index = faiss.read_index("faiss_index.bin")
|
16 |
embed_model = SentenceTransformer("all-MiniLM-L6-v2")
|
17 |
|
18 |
-
# β
Use your OpenRouter API key from environment
|
19 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
20 |
MODEL = "qwen/qwen-2.5-coder-32b-instruct:free"
|
21 |
|
@@ -67,7 +68,7 @@ async def chat_api(request: Request):
|
|
67 |
response = chat_fn(message, history)
|
68 |
return JSONResponse(content={"response": response})
|
69 |
|
70 |
-
# β
Gradio
|
71 |
demo = gr.ChatInterface(
|
72 |
fn=chat_fn,
|
73 |
title="CODEX MIRXA KAMRAN",
|
@@ -75,7 +76,10 @@ demo = gr.ChatInterface(
|
|
75 |
theme="soft"
|
76 |
)
|
77 |
|
78 |
-
# β
Mount Gradio
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
7 |
import numpy as np
|
8 |
from sentence_transformers import SentenceTransformer
|
9 |
import requests
|
10 |
+
import nest_asyncio
|
11 |
+
import uvicorn
|
12 |
|
13 |
# β
Load RAG-related files
|
14 |
with open("texts.json", "r", encoding="utf-8") as f:
|
|
|
17 |
index = faiss.read_index("faiss_index.bin")
|
18 |
embed_model = SentenceTransformer("all-MiniLM-L6-v2")
|
19 |
|
|
|
20 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
21 |
MODEL = "qwen/qwen-2.5-coder-32b-instruct:free"
|
22 |
|
|
|
68 |
response = chat_fn(message, history)
|
69 |
return JSONResponse(content={"response": response})
|
70 |
|
71 |
+
# β
Gradio Interface
|
72 |
demo = gr.ChatInterface(
|
73 |
fn=chat_fn,
|
74 |
title="CODEX MIRXA KAMRAN",
|
|
|
76 |
theme="soft"
|
77 |
)
|
78 |
|
79 |
+
# β
Mount Gradio at root
|
80 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
81 |
+
|
82 |
+
# β
For local dev (optional on Hugging Face)
|
83 |
+
if __name__ == "__main__":
|
84 |
+
nest_asyncio.apply()
|
85 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|