dwb2023 commited on
Commit
ae8a3e4
·
verified ·
1 Parent(s): 4f45e26

initial commit

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from datasets import load_dataset
4
+ from typing import Union, Dict, List, Optional
5
+ import pandas as pd
6
+ from smolagents import CodeAgent, HfApiModel, tool, GradioUI
7
+ from opentelemetry import trace
8
+ from opentelemetry.sdk.trace import TracerProvider
9
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
10
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
11
+ from openinference.instrumentation.smolagents import SmolagentsInstrumentor
12
+
13
+ PHOENIX_API_KEY = os.getenv("PHOENIX_API_KEY")
14
+ api_key = f"api_key={PHOENIX_API_KEY}"
15
+ os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = api_key
16
+ os.environ["PHOENIX_CLIENT_HEADERS"] = api_key
17
+ os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"
18
+
19
+ endpoint = "https://app.phoenix.arize.com/v1/traces"
20
+ trace_provider = TracerProvider()
21
+ trace_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint)))
22
+ SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
23
+
24
+ examples = [
25
+ ["Validate whether FANCA interacts with PALB2 in homologous recombination repair using BioGRID and PubMed evidence."],
26
+ ["Show the evolution of TP53-MDM2 interaction evidence from 2018-2023, highlighting key supporting papers."],
27
+ ["Compare BRCA2 interaction networks between human and mouse homologs, marking conserved relationships."],
28
+ ["Identify synthetic lethal partners for BRCA1-deficient cancers with confidence > 0.9 and clinical trial associations."],
29
+ ["Find novel VHL interactors proposed in 2023 PubMed articles not yet in BioGRID."],
30
+ ["Visualize the ATM interaction network with nodes sized by betweenness centrality and colored by validation source."],
31
+ ["Explain the Fanconi Anemia pathway and show its core components with experimental validation status."],
32
+ ["Correlate TP53BP1 protein interactions with mRNA co-expression patterns in TCGA breast cancer data."],
33
+ ["Identify high-betweenness nodes in the KRAS interaction network with druggable protein products."],
34
+ ["List all interactions with conflicting evidence between BioGRID and STRING, sorted by confidence delta."],
35
+ ]
36
+
37
+ class GradioUIWithExamples(GradioUI):
38
+ def __init__(self, agent, examples=None, **kwargs):
39
+ super().__init__(agent, **kwargs)
40
+ self.examples = examples
41
+
42
+ def build_interface(self):
43
+ with gr.Blocks() as demo:
44
+ gr.Markdown("## Biomedical Knowledge Graph")
45
+ gr.Markdown("""
46
+ An experimental knowledge graph platform that transforms fragmented biomedical data into insight.
47
+ """)
48
+
49
+ input_box = gr.Textbox(
50
+ label="Your Question",
51
+ placeholder="e.g., 'Find novel VHL interactors proposed in 2023 PubMed articles not yet in BioGRID.'"
52
+ )
53
+ output_box = gr.Textbox(
54
+ label="Analysis Results",
55
+ placeholder="Response will appear here...",
56
+ interactive=False,
57
+ )
58
+ submit_button = gr.Button("Submit")
59
+
60
+ submit_button.click(
61
+ self.agent.run,
62
+ inputs=input_box,
63
+ outputs=output_box,
64
+ )
65
+
66
+ if self.examples:
67
+ gr.Markdown("### Examples")
68
+ for example in self.examples:
69
+ gr.Button(example[0]).click(
70
+ lambda x=example[0]: x,
71
+ inputs=[],
72
+ outputs=input_box,
73
+ )
74
+ return demo
75
+
76
+ def launch(self):
77
+ demo = self.build_interface()
78
+ demo.launch()
79
+
80
+ model = HfApiModel()
81
+ agent = CodeAgent(
82
+ tools=[],
83
+ model=model,
84
+ additional_authorized_imports=["gradio","pandas","numpy"],
85
+ add_base_tools=True
86
+ )
87
+
88
+ interface = GradioUIWithExamples(agent, examples=examples)
89
+ interface.launch()