File size: 5,283 Bytes
ae8a3e4
 
 
 
b78d488
ae8a3e4
 
 
 
 
ad57236
 
 
 
 
 
ae8a3e4
 
3de4163
ae8a3e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197f9ec
ae8a3e4
 
197f9ec
 
 
 
 
 
 
 
 
d16ddfd
197f9ec
 
 
 
 
 
 
 
 
 
 
 
d16ddfd
ae8a3e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427de89
ae8a3e4
 
 
197f9ec
ae8a3e4
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import gradio as gr
from typing import Union, Dict, List, Optional
import pandas as pd
from smolagents import CodeAgent, HfApiModel, tool, GradioUI
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from openinference.semconv.resource import ResourceAttributes
from opentelemetry.sdk.resources import Resource

resource = Resource(attributes={
    ResourceAttributes.PROJECT_NAME: 'hf-parsimony'
})

PHOENIX_API_KEY = os.getenv("PHOENIX_API_KEY")
HF_TOKEN=os.getenv("HF_TOKEN")
api_key = f"api_key={PHOENIX_API_KEY}"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = api_key
os.environ["PHOENIX_CLIENT_HEADERS"] = api_key
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"

endpoint = "https://app.phoenix.arize.com/v1/traces"
trace_provider = TracerProvider()
trace_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint)))
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)

examples = [
    ["Validate whether FANCA interacts with PALB2 in homologous recombination repair using BioGRID and PubMed evidence."],
    ["Show the evolution of TP53-MDM2 interaction evidence from 2018-2023, highlighting key supporting papers."],
    ["Compare BRCA2 interaction networks between human and mouse homologs, marking conserved relationships."],
    ["Identify synthetic lethal partners for BRCA1-deficient cancers with confidence > 0.9 and clinical trial associations."],
    ["Find novel VHL interactors proposed in 2023 PubMed articles not yet in BioGRID."],
    ["Visualize the ATM interaction network with nodes sized by betweenness centrality and colored by validation source."],
    ["Explain the Fanconi Anemia pathway and show its core components with experimental validation status."],
    ["Correlate TP53BP1 protein interactions with mRNA co-expression patterns in TCGA breast cancer data."],
    ["Identify high-betweenness nodes in the KRAS interaction network with druggable protein products."],
    ["List all interactions with conflicting evidence between BioGRID and STRING, sorted by confidence delta."],
]

class GradioUIWithExamples(GradioUI):
    def __init__(self, agent, examples=None, **kwargs):
        super().__init__(agent, **kwargs)
        self.examples = examples


    def build_interface(self):
        with gr.Blocks() as demo:
            # Title Section
            gr.Markdown("## From Answers to Insight - Architecting Evolvable Agentic Systems")

            # Description Section
            gr.Markdown(
                """
                **πŸ”¬ Architectural Blueprint**: *Production systems require intentional design - combining smolagents' efficiency with Phoenix observability, powered by ontology-driven prompting patterns.*
                """
            )

            # Core Innovation Vectors Section
            with gr.Accordion("Core Innovation Vectors", open=True):
                gr.Markdown(
                    """
                    - βœ… **Competency Question Engine**: Structured prompting using domain vocabulary
                    - βœ… **Telemetry-First Core**: Phoenix spans capturing full evidence chains, establishing OpenTelemetry metrics pipeline for performance benchmarking
                    - βœ… **Domain Foundation**: Smolagents + biomedical vocabulary layer
                    - πŸ› οΈ **Human-in-the-Loop Evolution**: Gradio UI with human feedback capture
                    - πŸ› οΈ **Benchmarking Rigor**: Validation scorecards and audit framework
                    - πŸ› οΈ **Domain Insight Engine**: Knowledge graph grounding and multimodal evidence synthesis
                    """
                )


            input_box = gr.Textbox(
                label="Your Question",
                placeholder="e.g., 'Find novel VHL interactors proposed in 2023 PubMed articles not yet in BioGRID.'"
            )
            output_box = gr.Textbox(
                label="Analysis Results",
                placeholder="Response will appear here...",
                interactive=False,
            )
            submit_button = gr.Button("Submit")

            submit_button.click(
                self.agent.run,
                inputs=input_box,
                outputs=output_box,
            )

            if self.examples:
                gr.Markdown("### Examples")
                for example in self.examples:
                    gr.Button(example[0]).click(
                        lambda x=example[0]: x,
                        inputs=[],
                        outputs=input_box,
                    )
        return demo

    def launch(self):
        demo = self.build_interface()
        demo.launch()

model = HfApiModel(model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B', token=HF_TOKEN)
agent = CodeAgent(
    tools=[],
    model=model,
    additional_authorized_imports=["gradio","pandas","numpy","datasets","duckdb","json","streamlit","requests","json"],
    add_base_tools=True
)

interface = GradioUIWithExamples(agent, examples=examples)
interface.launch()