Skip to content

Commit 8ec5163

Browse files
committed
update gradio launch
1 parent 26caba9 commit 8ec5163

File tree

5 files changed

+123
-127
lines changed

5 files changed

+123
-127
lines changed

.github/workflows/update_space.yml

+12-66
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,28 @@
1-
name: Deploy to Hugging Face Spaces
1+
name: Run Python script
22

33
on:
44
push:
55
branches:
66
- main
77

88
jobs:
9-
deploy:
9+
build:
1010
runs-on: ubuntu-latest
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v2
1515

16-
- name: Set up Conda
17-
uses: conda-incubator/setup-miniconda@v2
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
1818
with:
19-
activate-environment: kg4s
20-
environment-file: environment.yml
21-
auto-activate-base: false
22-
use-mamba: true
19+
python-version: '3.9'
2320

24-
- name: Verify Conda installation
25-
shell: bash -l {0}
26-
run: |
27-
conda info
28-
conda list
21+
- name: Install Gradio
22+
run: python -m pip install gradio
2923

30-
- name: Install huggingface_hub
31-
shell: bash -l {0}
32-
run: |
33-
pip install huggingface_hub
34-
pip list
24+
- name: Log in to Hugging Face
25+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
3526

36-
- name: Deploy to Hugging Face Spaces
37-
env:
38-
HF_TOKEN: ${{ secrets.HF_TOKEN }}
39-
shell: bash -l {0}
40-
run: |
41-
python - <<EOF
42-
import os
43-
import sys
44-
from huggingface_hub import HfApi
45-
46-
print("Python script started")
47-
print(f"Python version: {sys.version}")
48-
print(f"Current working directory: {os.getcwd()}")
49-
print(f"Contents of current directory: {os.listdir('.')}")
50-
51-
sys.path.append('scripts')
52-
print(f"Updated sys.path: {sys.path}")
53-
print(f"Contents of scripts directory: {os.listdir('scripts')}")
54-
55-
print("Importing demo from run_db_interface")
56-
from run_db_interface import demo
57-
print("Demo imported successfully")
58-
59-
api = HfApi()
60-
print("HfApi initialized")
61-
62-
print("Creating/verifying repository")
63-
api.create_repo(
64-
repo_id="abby101/xurveyor-0",
65-
repo_type="space",
66-
space_sdk="gradio",
67-
token="$HF_TOKEN"
68-
)
69-
print("Repository created or verified")
70-
71-
print("Starting deployment")
72-
demo.deploy(
73-
repo_id="abby101/xurveyor-0",
74-
hf_token="$HF_TOKEN",
75-
)
76-
print("Deployment completed")
77-
EOF
78-
79-
- name: Check Hugging Face Space
80-
run: |
81-
echo "Deployment process completed. Please check your Hugging Face Space at https://huggingface.co/spaces/abby101/xurveyor-0"
82-
echo "If the space is not updated, please check the logs above for any errors."
27+
- name: Deploy to Spaces
28+
run: gradio deploy

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: surveyor-0
3+
app_file: scripts/run_db_interface.py
4+
sdk: gradio
5+
sdk_version: 4.40.0
6+
---
17
# Mapping the Data Landscape For Generalizable Scientific Models
28

39
We introduce a method to build a knowledge base to store structured information extracted from scientific publications, datasets and articles by leveraging large language models!

app.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
import os
3+
4+
sys.stdout.reconfigure(line_buffering=True)
5+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
6+
7+
from scripts.run_db_interface import launch
8+
9+
if __name__ == "__main__":
10+
launch()

run_tool.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#SBATCH --partition=gen
3+
#SBATCH --nodes=1
4+
#SBATCH --ntasks-per-node=1
5+
#SBATCH --cpus-per-task=10
6+
#SBATCH --mem=50G
7+
#SBATCH --time=7-00:00:00
8+
#SBATCH --output=slurm_logs/%x-%j.out
9+
#SBATCH --error=slurm_logs/%x-%j.err
10+
#SBATCH --job-name=gradio-tool
11+
12+
module --force purge
13+
module load modules/2.2-20230808 modules/2.3-20240529
14+
module load gcc/10.3.0 cuda/12.1.1 python/3.11.7
15+
16+
cd /mnt/home/adas1/projects/knowledge-graph/kg-for-science
17+
conda init
18+
conda activate kg4s
19+
python -u app.py

scripts/run_db_interface.py

+76-61
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import re
88
import sys
99
import sqlite3
10+
import time
1011

1112
from plotly.subplots import make_subplots
1213
from tabulate import tabulate
1314

1415
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15-
from create_db import ArxivDatabase
1616
from config import DEFAULT_TABLES_DIR, DEFAULT_INTERFACE_MODEL_ID, canned_queries
17+
from scripts.create_db import ArxivDatabase
1718
from src.utils.utils import set_env_vars
1819

1920
db = None
@@ -216,71 +217,85 @@ def load_database_with_graphs(db_name):
216217
}
217218
"""
218219

219-
with gr.Blocks(css=css) as demo:
220-
gr.Markdown("# ArXiv Database Query Interface")
221220

222-
with gr.Row():
223-
db_dropdown = gr.Dropdown(
224-
choices=get_available_databases(), label="Select Database"
221+
def launch():
222+
with gr.Blocks(css=css) as demo:
223+
gr.Markdown("# ArXiv Database Query Interface")
224+
225+
with gr.Row():
226+
db_dropdown = gr.Dropdown(
227+
choices=get_available_databases(), label="Select Database"
228+
)
229+
load_db_btn = gr.Button("Load Database", size="sm")
230+
status = gr.Textbox(label="Status")
231+
232+
with gr.Row():
233+
graph_output = gr.Plot(label="Concept Co-occurrence Graph")
234+
235+
with gr.Row():
236+
wrap_checkbox = gr.Checkbox(label="Wrap long text", value=False)
237+
canned_query_dropdown = gr.Dropdown(
238+
choices=[q[0] for q in canned_queries], label="Select Query", scale=3
239+
)
240+
limit_input = gr.Number(
241+
label="Limit", value=10000, step=1, minimum=1, scale=1
242+
)
243+
selected_query = gr.Textbox(
244+
label="Selected Query",
245+
interactive=False,
246+
scale=2,
247+
show_label=True,
248+
show_copy_button=True,
249+
elem_id="selected-query",
250+
)
251+
canned_query_submit = gr.Button("Submit Query", size="sm", scale=1)
252+
253+
with gr.Row():
254+
sql_input = gr.Textbox(label="Custom SQL Query", lines=3, scale=4)
255+
sql_submit = gr.Button("Submit Custom SQL", size="sm", scale=1)
256+
257+
output = gr.DataFrame(label="Results", wrap=True)
258+
259+
def update_selected_query(query_description):
260+
for desc, sql in canned_queries:
261+
if desc == query_description:
262+
return sql
263+
return ""
264+
265+
def submit_canned_query(query_description, limit, wrap):
266+
for desc, sql in canned_queries:
267+
if desc == query_description:
268+
return query_db(sql, True, limit, wrap)
269+
return pd.DataFrame({"Error": ["Selected query not found."]})
270+
271+
load_db_btn.click(
272+
load_database_with_graphs,
273+
inputs=[db_dropdown],
274+
outputs=[status, graph_output],
225275
)
226-
load_db_btn = gr.Button("Load Database", size="sm")
227-
status = gr.Textbox(label="Status")
228-
229-
with gr.Row():
230-
graph_output = gr.Plot(label="Concept Co-occurrence Graph")
231-
232-
with gr.Row():
233-
wrap_checkbox = gr.Checkbox(label="Wrap long text", value=False)
234-
canned_query_dropdown = gr.Dropdown(
235-
choices=[q[0] for q in canned_queries], label="Select Query", scale=3
276+
canned_query_dropdown.change(
277+
update_selected_query,
278+
inputs=[canned_query_dropdown],
279+
outputs=[selected_query],
236280
)
237-
limit_input = gr.Number(label="Limit", value=10000, step=1, minimum=1, scale=1)
238-
selected_query = gr.Textbox(
239-
label="Selected Query",
240-
interactive=False,
241-
scale=2,
242-
show_label=True,
243-
show_copy_button=True,
244-
elem_id="selected-query",
281+
canned_query_submit.click(
282+
submit_canned_query,
283+
inputs=[canned_query_dropdown, limit_input, wrap_checkbox],
284+
outputs=output,
285+
)
286+
sql_submit.click(
287+
query_db,
288+
inputs=[sql_input, gr.Checkbox(value=True), limit_input, wrap_checkbox],
289+
outputs=output,
245290
)
246-
canned_query_submit = gr.Button("Submit Query", size="sm", scale=1)
247-
248-
with gr.Row():
249-
sql_input = gr.Textbox(label="Custom SQL Query", lines=3, scale=4)
250-
sql_submit = gr.Button("Submit Custom SQL", size="sm", scale=1)
251-
252-
output = gr.DataFrame(label="Results", wrap=True)
253-
254-
def update_selected_query(query_description):
255-
for desc, sql in canned_queries:
256-
if desc == query_description:
257-
return sql
258-
return ""
259-
260-
def submit_canned_query(query_description, limit, wrap):
261-
for desc, sql in canned_queries:
262-
if desc == query_description:
263-
return query_db(sql, True, limit, wrap)
264-
return pd.DataFrame({"Error": ["Selected query not found."]})
265291

266-
load_db_btn.click(
267-
load_database_with_graphs, inputs=[db_dropdown], outputs=[status, graph_output]
268-
)
269-
canned_query_dropdown.change(
270-
update_selected_query, inputs=[canned_query_dropdown], outputs=[selected_query]
271-
)
272-
canned_query_submit.click(
273-
submit_canned_query,
274-
inputs=[canned_query_dropdown, limit_input, wrap_checkbox],
275-
outputs=output,
276-
)
277-
sql_submit.click(
278-
query_db,
279-
inputs=[sql_input, gr.Checkbox(value=True), limit_input, wrap_checkbox],
280-
outputs=output,
292+
print("Launching Gradio app...", flush=True)
293+
demo.launch(share=True)
294+
print(
295+
"Gradio app launched. If you don't see a URL above, there might be network restrictions.",
296+
flush=True,
281297
)
282298

283-
if __name__ == "__main__":
284-
demo.launch(share=True)
285299

286-
demo.launch()
300+
if __name__ == "__main__":
301+
launch()

0 commit comments

Comments
 (0)