File size: 2,421 Bytes
e44d530
f18c30e
676eb03
f18c30e
 
 
f39d1fb
ab5563a
f18c30e
ab5563a
f18c30e
676eb03
 
f18c30e
 
 
 
 
ab5563a
f18c30e
 
 
676eb03
ab5563a
f18c30e
 
 
 
 
f39d1fb
ab5563a
f39d1fb
ab5563a
f39d1fb
ab5563a
 
 
 
 
676eb03
e44d530
ab5563a
f39d1fb
e44d530
ab5563a
 
f39d1fb
ab5563a
 
f18c30e
 
 
ab5563a
 
 
 
 
e44d530
 
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
import gradio as gr
from inference import get_evo_response, get_gpt_response
from logger import log_feedback
import retrain
import pandas as pd
import os

# πŸ” Advisor core logic
def advisor_interface(query, context, feedback_choice):
    evo_output, evo_reasoning = get_evo_response(query, context, enable_search=True)
    gpt_output = get_gpt_response(query, context)

    if feedback_choice != "No feedback":
        label = 1 if feedback_choice == "πŸ‘ Helpful" else 0
        log_feedback(query, context, evo_output, label)

    return evo_reasoning, gpt_output, load_history()

# πŸ” Retrain logic
def retrain_evo():
    retrain.fine_tune_on_feedback()
    return "βœ… Evo retrained on feedback.", load_history()

# πŸ“œ Feedback log viewer
def load_history():
    if os.path.exists("feedback_log.csv"):
        df = pd.read_csv("feedback_log.csv")
        return df.tail(10).to_markdown(index=False)
    return "No history available yet."

# 🧠 UI
with gr.Blocks() as demo:
    gr.Markdown("## 🧠 EvoRAG – Retrieval-Augmented Adaptive AI for Finance")

    with gr.Accordion("πŸ“Œ Ask a Financial Question", open=True):
        with gr.Row():
            query = gr.Textbox(label="πŸ“ Question", placeholder="e.g. Should we reduce exposure to Fund A?")
        with gr.Row():
            context = gr.Textbox(label="πŸ“‚ Memo, Policy, or News Context", placeholder="e.g. Tech Fund A underperformed by 3.2%...")

    with gr.Row():
        feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful", "No feedback"], label="πŸ“Š Was Evo’s answer useful?", value="No feedback")

    with gr.Row():
        evo_out = gr.Textbox(label="πŸ”¬ EvoRAG Suggestion (with reasoning)", lines=4)
        gpt_out = gr.Textbox(label="πŸ€– GPT-3.5 Suggestion", lines=4)

    run_button = gr.Button("πŸš€ Run Advisors")
    run_button.click(fn=advisor_interface, inputs=[query, context, feedback], outputs=[evo_out, gpt_out, gr.Textbox(label="πŸ“œ Recent Feedback Log")])

    gr.Markdown("---")

    with gr.Accordion("πŸ” Evo Live Retraining", open=False):
        retrain_button = gr.Button("πŸ“š Retrain Evo Now from Feedback")
        retrain_output = gr.Textbox(label="πŸ› οΈ Retrain Status", interactive=False)
        history_output = gr.Textbox(label="πŸ“œ Recent Feedback Log", interactive=False)
        retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_output, history_output])

demo.launch()