Spaces:
Runtime error
Runtime error
Commit
·
c77c9f7
1
Parent(s):
8bbf037
- __pycache__/main.cpython-310.pyc +0 -0
- main.py +15 -5
__pycache__/main.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ
|
|
|
main.py
CHANGED
|
@@ -7,7 +7,6 @@ import threading
|
|
| 7 |
import streamlit as st # Import Streamlit
|
| 8 |
import queue
|
| 9 |
|
| 10 |
-
|
| 11 |
def generate_answer(question, previous_answers, model_name, open_router_key, openai_api_key):
|
| 12 |
"""Generates an answer to a question using the specified language model."""
|
| 13 |
gen_prompt = create_gen_prompt(question, previous_answers)
|
|
@@ -38,6 +37,7 @@ def evaluate_answer(question, new_answer, open_router_key, openai_api_key):
|
|
| 38 |
|
| 39 |
def process_question(question, model_name, open_router_key, openai_api_key, result_queue):
|
| 40 |
start_time = time.time()
|
|
|
|
| 41 |
previous_answers = []
|
| 42 |
question_novelty = 0
|
| 43 |
|
|
@@ -52,12 +52,15 @@ def process_question(question, model_name, open_router_key, openai_api_key, resu
|
|
| 52 |
break
|
| 53 |
|
| 54 |
if coherence_score <= 3:
|
| 55 |
-
|
|
|
|
| 56 |
break
|
| 57 |
|
| 58 |
novelty_score = get_novelty_score(new_answer, previous_answers, openai_api_key)
|
| 59 |
|
| 60 |
if novelty_score < 0.1:
|
|
|
|
|
|
|
| 61 |
break
|
| 62 |
|
| 63 |
# Append results to the queue instead of using st.write
|
|
@@ -66,7 +69,15 @@ def process_question(question, model_name, open_router_key, openai_api_key, resu
|
|
| 66 |
"question": question,
|
| 67 |
"answer": new_answer,
|
| 68 |
"coherence_score": coherence_score,
|
| 69 |
-
"novelty_score": novelty_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
})
|
| 71 |
|
| 72 |
previous_answers.append(new_answer)
|
|
@@ -75,7 +86,6 @@ def process_question(question, model_name, open_router_key, openai_api_key, resu
|
|
| 75 |
except Exception as e:
|
| 76 |
result_queue.put({"type": "error", "message": str(e)})
|
| 77 |
|
| 78 |
-
|
| 79 |
time_taken = time.time() - start_time
|
| 80 |
result_queue.put({
|
| 81 |
"type": "summary",
|
|
@@ -84,7 +94,6 @@ def process_question(question, model_name, open_router_key, openai_api_key, resu
|
|
| 84 |
"time_taken": time_taken
|
| 85 |
})
|
| 86 |
|
| 87 |
-
|
| 88 |
return question_novelty, [
|
| 89 |
{
|
| 90 |
"question": question,
|
|
@@ -144,6 +153,7 @@ def benchmark_model_multithreaded(model_name, questions, open_router_key, openai
|
|
| 144 |
st.write(f"<span style='color:green'>Coherence Score: {result['coherence_score']}</span>",
|
| 145 |
unsafe_allow_html=True)
|
| 146 |
st.write(f"**Novelty Score:** {result['novelty_score']}")
|
|
|
|
| 147 |
elif result["type"] == "summary":
|
| 148 |
st.write(f"<span style='color:blue'>Total novelty score for question '{result['question']}': {result['total_novelty']}</span>",
|
| 149 |
unsafe_allow_html=True)
|
|
|
|
| 7 |
import streamlit as st # Import Streamlit
|
| 8 |
import queue
|
| 9 |
|
|
|
|
| 10 |
def generate_answer(question, previous_answers, model_name, open_router_key, openai_api_key):
|
| 11 |
"""Generates an answer to a question using the specified language model."""
|
| 12 |
gen_prompt = create_gen_prompt(question, previous_answers)
|
|
|
|
| 37 |
|
| 38 |
def process_question(question, model_name, open_router_key, openai_api_key, result_queue):
|
| 39 |
start_time = time.time()
|
| 40 |
+
# st.write(f"<span style='color:red'>{question}</span>", unsafe_allow_html=True)
|
| 41 |
previous_answers = []
|
| 42 |
question_novelty = 0
|
| 43 |
|
|
|
|
| 52 |
break
|
| 53 |
|
| 54 |
if coherence_score <= 3:
|
| 55 |
+
# st.write("<span style='color:yellow'>Output is incoherent. Moving to next question.</span>",
|
| 56 |
+
# unsafe_allow_html=True)
|
| 57 |
break
|
| 58 |
|
| 59 |
novelty_score = get_novelty_score(new_answer, previous_answers, openai_api_key)
|
| 60 |
|
| 61 |
if novelty_score < 0.1:
|
| 62 |
+
# st.write("<span style='color:yellow'>Output is redundant. Moving to next question.</span>",
|
| 63 |
+
# unsafe_allow_html=True)
|
| 64 |
break
|
| 65 |
|
| 66 |
# Append results to the queue instead of using st.write
|
|
|
|
| 69 |
"question": question,
|
| 70 |
"answer": new_answer,
|
| 71 |
"coherence_score": coherence_score,
|
| 72 |
+
"novelty_score": novelty_score,
|
| 73 |
+
"results": [
|
| 74 |
+
{
|
| 75 |
+
"question": question,
|
| 76 |
+
"answers": previous_answers.copy() + [new_answer], # Include the new answer
|
| 77 |
+
"coherence_score": coherence_score,
|
| 78 |
+
"novelty_score": question_novelty + novelty_score # Accumulate novelty score
|
| 79 |
+
}
|
| 80 |
+
]
|
| 81 |
})
|
| 82 |
|
| 83 |
previous_answers.append(new_answer)
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
result_queue.put({"type": "error", "message": str(e)})
|
| 88 |
|
|
|
|
| 89 |
time_taken = time.time() - start_time
|
| 90 |
result_queue.put({
|
| 91 |
"type": "summary",
|
|
|
|
| 94 |
"time_taken": time_taken
|
| 95 |
})
|
| 96 |
|
|
|
|
| 97 |
return question_novelty, [
|
| 98 |
{
|
| 99 |
"question": question,
|
|
|
|
| 153 |
st.write(f"<span style='color:green'>Coherence Score: {result['coherence_score']}</span>",
|
| 154 |
unsafe_allow_html=True)
|
| 155 |
st.write(f"**Novelty Score:** {result['novelty_score']}")
|
| 156 |
+
results.extend(result["results"]) # Add results here
|
| 157 |
elif result["type"] == "summary":
|
| 158 |
st.write(f"<span style='color:blue'>Total novelty score for question '{result['question']}': {result['total_novelty']}</span>",
|
| 159 |
unsafe_allow_html=True)
|