Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from response_scoring import score_response
|
| 3 |
+
from roi_calculator import calculate_roi, Model
|
| 4 |
+
from semantic_memory import SemanticMemory
|
| 5 |
+
|
| 6 |
+
memory_system = SemanticMemory()
|
| 7 |
+
|
| 8 |
+
class Scenario:
|
| 9 |
+
def __init__(self, expected, context):
|
| 10 |
+
self.expected = expected
|
| 11 |
+
self.context = context
|
| 12 |
+
|
| 13 |
+
def evaluate(ai_response, scenario_text, expected_text,
|
| 14 |
+
usage, current_cost, recommended_cost):
|
| 15 |
+
|
| 16 |
+
scenario = Scenario(expected_text, scenario_text)
|
| 17 |
+
scores = score_response(ai_response, scenario)
|
| 18 |
+
|
| 19 |
+
current_model = Model("CurrentModel", current_cost)
|
| 20 |
+
recommended_model = Model("RecommendedModel", recommended_cost)
|
| 21 |
+
roi = calculate_roi(usage, current_model, recommended_model)
|
| 22 |
+
|
| 23 |
+
memory_system.store_memory(f"Scenario: {scenario_text}\nResponse: {ai_response}")
|
| 24 |
+
retrieved = memory_system.retrieve_relevant(scenario_text)
|
| 25 |
+
|
| 26 |
+
return scores, roi, retrieved
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=evaluate,
|
| 30 |
+
inputs=[
|
| 31 |
+
gr.Textbox(label="AI Response", lines=3),
|
| 32 |
+
gr.Textbox(label="Scenario Context", lines=2),
|
| 33 |
+
gr.Textbox(label="Expected Output", lines=2),
|
| 34 |
+
gr.Number(label="Customer Usage per Day"),
|
| 35 |
+
gr.Number(label="Current Model Cost per Call ($)"),
|
| 36 |
+
gr.Number(label="Recommended Model Cost per Call ($)")
|
| 37 |
+
],
|
| 38 |
+
outputs=[
|
| 39 |
+
gr.JSON(label="Response Scores"),
|
| 40 |
+
gr.JSON(label="ROI Calculation"),
|
| 41 |
+
gr.JSON(label="Relevant Memories")
|
| 42 |
+
],
|
| 43 |
+
title="AI Evaluator + ROI + Memory Demo"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
iface.launch()
|