Spaces:
Sleeping
Sleeping
update setup notes
Browse files- .gitignore +2 -1
- demo.py +39 -0
- setup.sh +15 -0
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
/data/
|
|
|
|
|
|
| 1 |
+
/data/
|
| 2 |
+
*__pycache__*
|
demo.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
| 7 |
+
# Call the core inference function, passing the pre-loaded assets
|
| 8 |
+
trajectory, answer = run_search(question)
|
| 9 |
+
answer_string = f"Final answer: {answer.strip()}"
|
| 10 |
+
answer_string += f"\n\n====== Trajectory of reasoning steps ======\n{trajectory.strip()}"
|
| 11 |
+
return answer_string
|
| 12 |
+
except Exception as e:
|
| 13 |
+
# Basic error handling for the Gradio interface
|
| 14 |
+
return f"An error occurred: {e}. Please check the console for more details."
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=gradio_answer,
|
| 19 |
+
inputs=gr.Textbox(
|
| 20 |
+
lines=3,
|
| 21 |
+
label="Enter your question",
|
| 22 |
+
placeholder="e.g., Who invented the telephone?"
|
| 23 |
+
),
|
| 24 |
+
outputs=gr.Textbox(
|
| 25 |
+
label="Answer",
|
| 26 |
+
show_copy_button=True, # Allow users to easily copy the answer
|
| 27 |
+
elem_id="answer_output" # Optional: for custom CSS/JS targeting
|
| 28 |
+
),
|
| 29 |
+
title="Demo of AutoRefine: Question Answering with Search and Refine During Thinking",
|
| 30 |
+
description=("Ask a question and this model will use a multi-turn reasoning and search mechanism to find the answer."),
|
| 31 |
+
examples=question_list, # Use the list of example questions
|
| 32 |
+
live=False, # Set to True if you want real-time updates as user types
|
| 33 |
+
allow_flagging="never", # Disable flagging functionality
|
| 34 |
+
theme=gr.themes.Soft(), # Apply a clean theme
|
| 35 |
+
cache_examples=True, # Cache the examples for faster loading
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
iface.launch(share=True)
|
| 39 |
+
|
setup.sh
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Installation guidance for this space
|
| 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
|
| 9 |
+
python download_model.py
|
| 10 |
+
|
| 11 |
+
bash retrieval_launch.sh
|
| 12 |
+
# sanity check
|
| 13 |
+
python infer.py
|
| 14 |
+
python demo.py
|
| 15 |
+
```
|