Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,98 +1,62 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from inference import get_evo_response, get_gpt_response
|
| 3 |
-
import csv
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
LOG_PATH = "feedback_log.csv"
|
| 7 |
-
if LOG_PATH
|
| 8 |
-
os.makedirs(os.path.dirname(LOG_PATH) or ".", exist_ok=True)
|
| 9 |
-
if not os.path.exists(LOG_PATH):
|
| 10 |
-
with open(LOG_PATH, "w", newline="") as f:
|
| 11 |
-
writer = csv.writer(f)
|
| 12 |
-
writer.writerow(["question", "context", "evo_answer", "gpt_answer", "feedback"])
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
if len(options) != 2:
|
| 19 |
-
return "Please enter exactly two options (one per line).", "", "", "", "", history
|
| 20 |
-
|
| 21 |
-
evo_ans, reasoning, confidence, evo_context = get_evo_response(query, options, context_input)
|
| 22 |
-
gpt_ans = get_gpt_response(query, context_input)
|
| 23 |
-
|
| 24 |
-
entry = {
|
| 25 |
-
"Question": query,
|
| 26 |
-
"Context": context_input,
|
| 27 |
-
"Options": options,
|
| 28 |
-
"Evo Answer": evo_ans,
|
| 29 |
-
"Evo Score": reasoning,
|
| 30 |
-
"Confidence": f"{confidence:.2f}",
|
| 31 |
-
"Context Used": evo_context,
|
| 32 |
-
"GPT Answer": gpt_ans
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
history.insert(0, entry)
|
| 36 |
return (
|
| 37 |
-
|
| 38 |
reasoning,
|
| 39 |
-
evo_context,
|
| 40 |
-
|
| 41 |
-
"", # feedback placeholder
|
| 42 |
-
history
|
| 43 |
)
|
| 44 |
|
| 45 |
-
def
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
writer.writerow([question, context, evo_answer, gpt_answer, feedback])
|
| 49 |
-
return "β
Feedback submitted."
|
| 50 |
-
|
| 51 |
-
def render_history(history):
|
| 52 |
-
if not history:
|
| 53 |
-
return "No previous questions."
|
| 54 |
-
html = ""
|
| 55 |
-
for h in history[:5]:
|
| 56 |
-
html += f"<b>Q:</b> {h['Question']}<br>"
|
| 57 |
-
html += f"<b>Options:</b> {', '.join(h['Options'])}<br>"
|
| 58 |
-
html += f"<b>Evo:</b> {h['Evo Answer']} ({h['Evo Score']})<br>"
|
| 59 |
-
html += f"<b>GPT:</b> {h['GPT Answer']}<br><hr>"
|
| 60 |
-
return html
|
| 61 |
|
| 62 |
with gr.Blocks(title="π§ EvoRAG β General-Purpose Adaptive AI with Web Reasoning") as demo:
|
| 63 |
gr.Markdown("## π§ EvoRAG β General-Purpose Adaptive AI with Web Reasoning")
|
| 64 |
-
gr.Markdown("Ask any question and compare Evoβs evolved reasoning with GPT-3.5. Evo uses online context + live evolution.")
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
feedback_status = gr.Markdown()
|
| 84 |
-
history_display = gr.HTML(label="π Recent History")
|
| 85 |
|
| 86 |
run_btn.click(
|
| 87 |
-
|
| 88 |
-
inputs=[query,
|
| 89 |
-
outputs=[
|
| 90 |
)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
submit_btn.click(
|
| 93 |
-
|
| 94 |
-
inputs=[
|
| 95 |
-
outputs=
|
| 96 |
)
|
| 97 |
|
| 98 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from inference import get_evo_response, get_gpt_response
|
|
|
|
| 3 |
import os
|
| 4 |
+
from logger import log_feedback
|
| 5 |
|
| 6 |
LOG_PATH = "feedback_log.csv"
|
| 7 |
+
os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True) if os.path.dirname(LOG_PATH) else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def process_inputs(query, option_1, option_2, user_context):
|
| 10 |
+
options = [option_1, option_2]
|
| 11 |
+
evo_answer, reasoning, confidence, evo_context = get_evo_response(query, options, user_context)
|
| 12 |
+
gpt_answer = get_gpt_response(query, user_context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return (
|
| 14 |
+
evo_answer,
|
| 15 |
reasoning,
|
| 16 |
+
f"Context used by Evo:\n{evo_context}",
|
| 17 |
+
gpt_answer
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
+
def feedback_submit(question, context, evo_answer, feedback):
|
| 21 |
+
log_feedback(question, context, evo_answer, feedback)
|
| 22 |
+
return "β
Feedback submitted. Thank you!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Blocks(title="π§ EvoRAG β General-Purpose Adaptive AI with Web Reasoning") as demo:
|
| 25 |
gr.Markdown("## π§ EvoRAG β General-Purpose Adaptive AI with Web Reasoning")
|
|
|
|
| 26 |
|
| 27 |
with gr.Row():
|
| 28 |
+
with gr.Column():
|
| 29 |
+
query = gr.Textbox(label="π Ask anything", placeholder="e.g. Who is the current president of the US?")
|
| 30 |
+
user_context = gr.Textbox(label="π Optional Context or Notes", placeholder="Paste extra info or leave blank")
|
| 31 |
+
option_1 = gr.Textbox(label="πΉ Option 1", placeholder="e.g. Donald Trump")
|
| 32 |
+
option_2 = gr.Textbox(label="πΈ Option 2", placeholder="e.g. Joe Biden")
|
| 33 |
+
run_btn = gr.Button("π Get Answers")
|
| 34 |
+
|
| 35 |
+
with gr.Column():
|
| 36 |
+
gr.Markdown("### π§ EvoRAG Suggestion")
|
| 37 |
+
evo_out = gr.Textbox(label="Answer (Evo)", interactive=False)
|
| 38 |
+
evo_reason = gr.Textbox(label="Reasoning", interactive=False)
|
| 39 |
+
evo_context_used = gr.Textbox(label="Context Used", lines=4, interactive=False)
|
| 40 |
+
|
| 41 |
+
gr.Markdown("### π€ GPT-3.5 Suggestion")
|
| 42 |
+
gpt_out = gr.Textbox(label="Answer (GPT-3.5)", interactive=False)
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
run_btn.click(
|
| 45 |
+
fn=process_inputs,
|
| 46 |
+
inputs=[query, option_1, option_2, user_context],
|
| 47 |
+
outputs=[evo_out, evo_reason, evo_context_used, gpt_out]
|
| 48 |
)
|
| 49 |
|
| 50 |
+
gr.Markdown("### π³οΈ Feedback")
|
| 51 |
+
with gr.Row():
|
| 52 |
+
feedback = gr.Radio(["π Helpful", "π Not Helpful"], label="Was Evoβs answer useful?")
|
| 53 |
+
submit_btn = gr.Button("π¬ Submit Feedback")
|
| 54 |
+
feedback_result = gr.Textbox(visible=False)
|
| 55 |
+
|
| 56 |
submit_btn.click(
|
| 57 |
+
fn=feedback_submit,
|
| 58 |
+
inputs=[query, user_context, evo_out, feedback],
|
| 59 |
+
outputs=[feedback_result]
|
| 60 |
)
|
| 61 |
|
| 62 |
demo.launch()
|