Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,58 +1,66 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from inference import get_evo_response, get_gpt_response
|
3 |
-
from logger import log_feedback
|
4 |
-
import retrain
|
5 |
import pandas as pd
|
6 |
import os
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
return
|
22 |
|
23 |
def load_history():
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
except ImportError:
|
29 |
-
return "π History available, but markdown rendering failed. Install `tabulate` for full view."
|
30 |
-
return "No history available yet."
|
31 |
|
32 |
with gr.Blocks() as demo:
|
33 |
-
gr.Markdown("
|
34 |
|
35 |
with gr.Row():
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
run_button.click(fn=advisor_interface, inputs=[question, context, options_text, feedback], outputs=[evo_out, gpt_out, gr.Textbox(label="π Recent History")])
|
50 |
-
|
51 |
-
gr.Markdown("---")
|
52 |
-
gr.Markdown("### π Retrain Evo from Feedback")
|
53 |
-
retrain_button = gr.Button("π Retrain Evo")
|
54 |
-
retrain_output = gr.Textbox(label="π οΈ Retrain Status")
|
55 |
-
history_output = gr.Textbox(label="π Recent History")
|
56 |
-
retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_output, history_output])
|
57 |
|
58 |
demo.launch()
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import gradio as gr
|
4 |
from inference import get_evo_response, get_gpt_response
|
|
|
|
|
5 |
import pandas as pd
|
6 |
import os
|
7 |
|
8 |
+
LOG_PATH = "feedback_log.csv"
|
9 |
+
os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
|
10 |
+
if not os.path.exists(LOG_PATH):
|
11 |
+
pd.DataFrame(columns=["question", "context", "option1", "option2", "evo_answer", "feedback"]).to_csv(LOG_PATH, index=False)
|
12 |
+
|
13 |
+
def advisor_interface(question, context, options_text, feedback=None):
|
14 |
+
options = [o.strip() for o in options_text.split("\n") if o.strip()]
|
15 |
+
if len(options) != 2:
|
16 |
+
return "Please enter exactly two options (one per line).", "", ""
|
17 |
|
18 |
+
option1, option2 = options
|
19 |
+
evo_answer, confidence, s1, s2 = get_evo_response(question, option1, option2)
|
20 |
+
gpt_output = get_gpt_response(question, option1, option2)
|
21 |
|
22 |
+
# Log feedback if given
|
23 |
+
if feedback:
|
24 |
+
df = pd.read_csv(LOG_PATH)
|
25 |
+
df = df.append({
|
26 |
+
"question": question,
|
27 |
+
"context": context,
|
28 |
+
"option1": option1,
|
29 |
+
"option2": option2,
|
30 |
+
"evo_answer": evo_answer,
|
31 |
+
"feedback": feedback
|
32 |
+
}, ignore_index=True)
|
33 |
+
df.to_csv(LOG_PATH, index=False)
|
34 |
|
35 |
+
evo_msg = f"Evo suggests: **{evo_answer}** (Confidence: {confidence:.2f})"
|
36 |
+
context_used = f"Option 1 Score: {s1:.2f}\nOption 2 Score: {s2:.2f}"
|
37 |
+
return evo_msg + "\n\n" + context_used, gpt_output, load_history()
|
38 |
|
39 |
def load_history():
|
40 |
+
df = pd.read_csv(LOG_PATH)
|
41 |
+
if df.empty:
|
42 |
+
return "No feedback yet."
|
43 |
+
return df.tail(10).to_markdown(index=False)
|
|
|
|
|
|
|
44 |
|
45 |
with gr.Blocks() as demo:
|
46 |
+
gr.Markdown("π§ **EvoRAG β General-Purpose Adaptive AI with Web Reasoning**")
|
47 |
|
48 |
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
question = gr.Textbox(label="π Ask anything")
|
51 |
+
context = gr.Textbox(label="π Optional Context or Notes", lines=2)
|
52 |
+
options = gr.Textbox(label="π§ Options (Enter two options, one per line)", placeholder="Option 1\nOption 2")
|
53 |
+
run_btn = gr.Button("π Run Advisors")
|
54 |
|
55 |
+
feedback = gr.Radio(["π Helpful", "π Not Helpful", "No feedback"], label="Was Evoβs answer useful?")
|
56 |
+
evo_out = gr.Markdown()
|
57 |
+
gpt_out = gr.Markdown()
|
58 |
+
history = gr.Markdown()
|
59 |
|
60 |
+
run_btn.click(
|
61 |
+
advisor_interface,
|
62 |
+
inputs=[question, context, options, feedback],
|
63 |
+
outputs=[evo_out, gpt_out, history]
|
64 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
demo.launch()
|