Spaces:
Sleeping
Sleeping
File size: 2,235 Bytes
e44d530 f18c30e 676eb03 f18c30e f39d1fb 75dd2e7 f18c30e 676eb03 f18c30e 676eb03 f18c30e f39d1fb 75dd2e7 f39d1fb 75dd2e7 676eb03 e44d530 75dd2e7 f39d1fb e44d530 75dd2e7 f39d1fb 75dd2e7 f18c30e 75dd2e7 f18c30e 75dd2e7 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 |
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(query, context, file, feedback_choice):
evo_output, evo_reasoning = get_evo_response(query, context, file)
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()
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")
return df.tail(10).to_markdown(index=False)
return "No history available yet."
with gr.Blocks() as demo:
gr.Markdown("## π§ EvoRAG β Retrieval-Augmented Adaptive AI (General Purpose)")
with gr.Row():
query = gr.Textbox(label="π Ask any question", placeholder="e.g. What are the effects of inflation?")
context = gr.Textbox(label="π Optional background notes or memos", placeholder="Paste policy, notes, or ideas...")
with gr.Row():
file = gr.File(label="π Upload optional file (.txt or .pdf)", file_types=[".txt", ".pdf"])
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=6)
gpt_out = gr.Textbox(label="π€ GPT-3.5 Suggestion", lines=6)
run_button = gr.Button("Run Advisors")
history_output = gr.Textbox(label="π Recent History")
run_button.click(fn=advisor_interface, inputs=[query, context, file, feedback], outputs=[evo_out, gpt_out, history_output])
gr.Markdown("---")
gr.Markdown("### π Retrain Evo on Feedback")
retrain_button = gr.Button("π Retrain Evo")
retrain_status = gr.Textbox(label="π οΈ Retrain Status")
retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_status, history_output])
demo.launch()
|