TEZv commited on
Commit
744e47b
·
verified ·
1 Parent(s): 9d753a9

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +46 -13
app.py CHANGED
@@ -1,18 +1,51 @@
1
  import gradio as gr
 
2
 
3
- def register_study(title, domain, sphere, pi):
4
- study_id = f"STU-{hash(title) % 10000:04d}"
5
- result = f"Study ID: {study_id}\nTitle: {title}\nDomain: {domain}\nSphere: {sphere}\nPI: {pi}\nStatus: registered\nDate: 2026-05-11"
6
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- with gr.Blocks(title="studyreg") as demo:
9
- gr.Markdown("# Study Registry Pre-register Your Study")
10
- title = gr.Textbox(label="Study Title")
11
- domain = gr.Dropdown(["biomedical","ml","climate","agriculture","economics","other"], label="Domain")
12
- sphere = gr.Dropdown(["Science","Entrepreneurship","Technology"], label="SET Sphere")
13
- pi = gr.Textbox(label="Principal Investigator")
14
- out = gr.Textbox(label="Registration Result")
15
- btn = gr.Button("Register Study")
16
- btn.click(register_study, [title, domain, sphere, pi], out)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  demo.launch()
 
1
  import gradio as gr
2
+ from studyreg import register, search, validate
3
 
4
+ def register_study(title, repo, tags_str, sphere, domain):
5
+ if not title.strip():
6
+ return "Please enter a study title."
7
+ tags = [t.strip() for t in tags_str.split(",") if t.strip()] if tags_str else []
8
+ study = register(title=title, repo=repo, tags=tags, sphere=sphere, domain=domain)
9
+ valid = validate(study)
10
+ output = f"**Study ID:** {study['id']}\n\n"
11
+ output += f"- Title: {study['title']}\n"
12
+ output += f"- Sphere: {study['sphere']}\n"
13
+ output += f"- Domain: {study['domain']}\n"
14
+ output += f"- Tags: {', '.join(study['tags']) or 'none'}\n"
15
+ output += f"- Status: {study['status']}\n"
16
+ output += f"- Date: {study['date']}\n\n"
17
+ if valid['valid']:
18
+ output += "✅ Study registration is valid"
19
+ else:
20
+ output += "⚠️ Issues:\n" + "\n".join(f"- {w}" for w in valid['warnings'])
21
+ return output
22
 
23
+ def search_studies(domain, sphere, status):
24
+ results = search(domain=domain or None, sphere=sphere or None, status=status or None)
25
+ if not results:
26
+ return "No studies found matching criteria."
27
+ output = f"**Found {len(results)} study(ies):**\n\n"
28
+ for s in results:
29
+ output += f"- **{s['id']}**: {s['title']} ({s['sphere']}, {s['domain']}) — {s['status']}\n"
30
+ return output
31
+
32
+ with gr.Blocks(title="studyreg — Study Registry", theme=gr.themes.Base()) as demo:
33
+ gr.Markdown("# Study Registry\nPre-register your computational studies for reproducibility\n[pip install studyreg](https://pypi.org/project/studyreg/) · [Source](https://github.com/K-RnD-Lab/SPHERE-III-TECHNOLOGY)")
34
+ with gr.Tab("Register"):
35
+ r_title = gr.Textbox(label="Study Title", placeholder="e.g. BRCA2 miRNA Oncology Study")
36
+ r_repo = gr.Textbox(label="Repository URL", placeholder="https://github.com/...")
37
+ r_tags = gr.Textbox(label="Tags (comma-separated)", placeholder="oncology, brca2, mirna")
38
+ r_sphere = gr.Dropdown(["S", "E", "T"], value="S", label="SET Sphere")
39
+ r_domain = gr.Dropdown(["biomedical", "ml", "climate", "agriculture", "economics", "other"], value="biomedical", label="Domain")
40
+ r_btn = gr.Button("Register Study", variant="primary")
41
+ r_out = gr.Markdown()
42
+ r_btn.click(register_study, [r_title, r_repo, r_tags, r_sphere, r_domain], r_out)
43
+ with gr.Tab("Search"):
44
+ s_domain = gr.Textbox(label="Domain (optional)")
45
+ s_sphere = gr.Dropdown(["", "S", "E", "T"], value="", label="Sphere (optional)")
46
+ s_status = gr.Dropdown(["", "registered", "completed", "withdrawn"], value="", label="Status (optional)")
47
+ s_btn = gr.Button("Search", variant="primary")
48
+ s_out = gr.Markdown()
49
+ s_btn.click(search_studies, [s_domain, s_sphere, s_status], s_out)
50
 
51
  demo.launch()