yrshi commited on
Commit
ca9a33f
·
1 Parent(s): 969257a

minor update the code

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. setup.sh +2 -2
app.py CHANGED
@@ -1,6 +1,37 @@
1
  import gradio as gr
2
  from infer import run_search, question_list
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def gradio_answer(question: str) -> str:
5
  print(f"\nReceived question for Gradio: {question}")
6
  try:
 
1
  import gradio as gr
2
  from infer import run_search, question_list
3
 
4
+ import subprocess
5
+ import time
6
+ import atexit
7
+ from urllib.parse import urlparse
8
+
9
+ # ... (keep all your other imports like transformers, torch, requests, re, gr) ...
10
+
11
+ # --- NEW: Server Launch Block ---
12
+ # Insert this block *before* you load the model
13
+ # -----------------------------------------------------------------
14
+ print("Attempting to start retrieval server...")
15
+
16
+ # Start the server as a background process
17
+ # subprocess.Popen does not block, unlike os.system
18
+ try:
19
+ server_process = subprocess.Popen(["bash", "retrieval_launch.sh"])
20
+ print(f"Server process started with PID: {server_process.pid}")
21
+
22
+ # Register a function to kill the server when app.py exits
23
+ def cleanup():
24
+ print("Shutting down retrieval server...")
25
+ server_process.terminate()
26
+ server_process.wait()
27
+ print("Server process terminated.")
28
+
29
+ atexit.register(cleanup)
30
+
31
+ except Exception as e:
32
+ print(f"Failed to start retrieval_launch.sh: {e}")
33
+ print("WARNING: The retrieval server may not be running.")
34
+
35
  def gradio_answer(question: str) -> str:
36
  print(f"\nReceived question for Gradio: {question}")
37
  try:
setup.sh CHANGED
@@ -2,7 +2,7 @@
2
 
3
  ```bash
4
  bash install_cuda.sh
5
- conda create -n faiss_env python=3.10 && conda activate faiss_env
6
  bash install_env.sh
7
 
8
  bash download_corpus.sh
@@ -11,5 +11,5 @@ python download_model.py
11
  bash retrieval_launch.sh
12
  # sanity check
13
  python infer.py
14
- python demo.py
15
  ```
 
2
 
3
  ```bash
4
  bash install_cuda.sh
5
+ # conda create -n faiss_env python=3.10 && conda activate faiss_env
6
  bash install_env.sh
7
 
8
  bash download_corpus.sh
 
11
  bash retrieval_launch.sh
12
  # sanity check
13
  python infer.py
14
+ GRADIO_SERVER_PORT=7890 python demo.py
15
  ```