mirxakamran893 commited on
Commit
b7552f5
Β·
verified Β·
1 Parent(s): 5836b9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
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 Chat Interface
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 in FastAPI
79
- @app.get("/")
80
- def gradio_app():
81
- return gr.mount_gradio_app(app, demo, path="/")
 
 
 
 
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)