File size: 2,544 Bytes
e44d530
f18c30e
676eb03
f18c30e
 
 
f39d1fb
3363688
 
 
 
676eb03
 
f18c30e
3363688
f18c30e
 
 
 
 
 
676eb03
f18c30e
 
 
3363688
 
 
 
f18c30e
f39d1fb
 
cb1e60f
f39d1fb
75dd2e7
3363688
 
 
e44d530
3363688
 
 
f39d1fb
e44d530
cb1e60f
 
75dd2e7
 
3363688
f18c30e
 
cb1e60f
75dd2e7
cb1e60f
 
 
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
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

def advisor_interface(question, context, options_text, feedback_choice):
    options = [opt.strip() for opt in options_text.split("\n") if opt.strip()]
    evo_output, evo_reasoning = get_evo_response(question, context, options)
    gpt_output = get_gpt_response(question, context, options)

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

    return evo_reasoning, gpt_output, load_history()

def retrain_evo():
    retrain.fine_tune_on_feedback()
    return "βœ… Evo retrained on feedback.", load_history()

def load_history():
    if os.path.exists("feedback_log.csv"):
        df = pd.read_csv("feedback_log.csv")
        try:
            return df.tail(10).to_markdown(index=False)
        except ImportError:
            return "πŸ“œ History available, but markdown rendering failed. Install `tabulate` for full view."
    return "No history available yet."

with gr.Blocks() as demo:
    gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with RAG + Web Search")

    with gr.Row():
        question = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. Who is the current president of the US?")
    with gr.Row():
        options_text = gr.Textbox(label="πŸ”’ Options (one per line)", placeholder="Option 1\nOption 2\nOption 3", lines=4)
    with gr.Row():
        context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", placeholder="Paste memo, article, or info here...", lines=4)

    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)")
        gpt_out = gr.Textbox(label="πŸ€– GPT-3.5 Suggestion")

    run_button = gr.Button("Run Advisors")
    run_button.click(fn=advisor_interface, inputs=[question, context, options_text, feedback], outputs=[evo_out, gpt_out, gr.Textbox(label="πŸ“œ Recent History")])

    gr.Markdown("---")
    gr.Markdown("### πŸ” Retrain Evo from Feedback")
    retrain_button = gr.Button("πŸ“š Retrain Evo")
    retrain_output = gr.Textbox(label="πŸ› οΈ Retrain Status")
    history_output = gr.Textbox(label="πŸ“œ Recent History")
    retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_output, history_output])

demo.launch()