Spaces:
Sleeping
Sleeping
Lumiin0us commited on
Added Evaluation to streamlit.py
Browse files- streamlit.py +34 -1
streamlit.py
CHANGED
|
@@ -3,6 +3,22 @@ import os
|
|
| 3 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 4 |
import streamlit as st
|
| 5 |
from agent.graph import app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
st.title("AI Research Assistant")
|
| 8 |
topic = st.text_input("Enter research topic:")
|
|
@@ -18,4 +34,21 @@ if st.button("Research"):
|
|
| 18 |
"reflection_passed": False,
|
| 19 |
"loop_count": 0
|
| 20 |
})
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 4 |
import streamlit as st
|
| 5 |
from agent.graph import app
|
| 6 |
+
from agent.state import ResearchState
|
| 7 |
+
from ragas import evaluate
|
| 8 |
+
from ragas.metrics import faithfulness, answer_relevancy
|
| 9 |
+
from datasets import Dataset
|
| 10 |
+
from ragas.llms import LangchainLLMWrapper
|
| 11 |
+
from ragas.embeddings import LangchainEmbeddingsWrapper
|
| 12 |
+
from langchain_groq import ChatGroq
|
| 13 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 14 |
+
|
| 15 |
+
evaluator_llm = LangchainLLMWrapper(
|
| 16 |
+
ChatGroq(model="llama-3.3-70b-versatile", api_key="", n=1)
|
| 17 |
+
)
|
| 18 |
+
evaluator_embeddings = LangchainEmbeddingsWrapper(
|
| 19 |
+
HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
|
| 23 |
st.title("AI Research Assistant")
|
| 24 |
topic = st.text_input("Enter research topic:")
|
|
|
|
| 34 |
"reflection_passed": False,
|
| 35 |
"loop_count": 0
|
| 36 |
})
|
| 37 |
+
|
| 38 |
+
dataset = Dataset.from_dict({
|
| 39 |
+
"question": [result['topic']],
|
| 40 |
+
"answer": [result['report']],
|
| 41 |
+
"contexts": [result['scraped_content']],
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
scores = evaluate(
|
| 45 |
+
dataset=dataset,
|
| 46 |
+
metrics=[faithfulness, answer_relevancy],
|
| 47 |
+
llm=evaluator_llm,
|
| 48 |
+
embeddings=evaluator_embeddings)
|
| 49 |
+
|
| 50 |
+
st.subheader("Report Quality Scores")
|
| 51 |
+
st.metric("Faithfulness", round(scores['faithfulness'][0], 2))
|
| 52 |
+
st.metric("Answer Relevancy", round(scores['answer_relevancy'][0], 2))
|
| 53 |
+
|
| 54 |
+
st.markdown(result['report'])
|