Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,26 +48,39 @@ def respond(
|
|
48 |
response += token
|
49 |
yield response, history + [(message, response)]
|
50 |
|
51 |
-
def
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
verdict_value = verdict_score * 5
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
return
|
71 |
|
72 |
def color_code(score):
|
73 |
if score > 50:
|
@@ -165,8 +178,10 @@ def chat_between_bots(system_message1, system_message2, max_tokens, temperature,
|
|
165 |
response1 = response1[:max_length]
|
166 |
response2 = response2[:max_length]
|
167 |
|
168 |
-
|
169 |
-
|
|
|
|
|
170 |
|
171 |
prosecutor_color = color_code(score1)
|
172 |
defense_color = color_code(score2)
|
@@ -174,26 +189,8 @@ def chat_between_bots(system_message1, system_message2, max_tokens, temperature,
|
|
174 |
prosecutor_score_color = f"<div class='score-box' style='background-color:{prosecutor_color};'>Score: {score1}</div>"
|
175 |
defense_score_color = f"<div class='score-box' style='background-color:{defense_color};'>Score: {score2}</div>"
|
176 |
|
177 |
-
outcome = generate_case_outcome(response1, response2)
|
178 |
-
|
179 |
return response1, response2, history1, history2, shared_history, outcome, prosecutor_score_color, defense_score_color
|
180 |
|
181 |
-
def generate_case_outcome(prosecutor_response, defense_response):
|
182 |
-
prompt = f"Prosecutor's Argument: {prosecutor_response}\nDefense Attorney's Argument: {defense_response}\n\nEvaluate both arguments and determine who won the case. Provide reasons for your decision."
|
183 |
-
evaluation = ""
|
184 |
-
for message in client.chat_completion(
|
185 |
-
[{"role": "system", "content": "You are a legal expert evaluating the arguments presented by the prosecution and the defense."},
|
186 |
-
{"role": "user", "content": prompt}],
|
187 |
-
max_tokens=512,
|
188 |
-
stream=True,
|
189 |
-
temperature=0.6,
|
190 |
-
top_p=0.95,
|
191 |
-
):
|
192 |
-
token = message.choices[0].delta.content
|
193 |
-
if token is not None:
|
194 |
-
evaluation += token
|
195 |
-
return evaluation
|
196 |
-
|
197 |
def update_pdf_gallery(pdf_files):
|
198 |
return pdf_files
|
199 |
|
|
|
48 |
response += token
|
49 |
yield response, history + [(message, response)]
|
50 |
|
51 |
+
def generate_case_outcome(prosecutor_response, defense_response):
|
52 |
+
prompt = f"Prosecutor's Argument: {prosecutor_response}\nDefense Attorney's Argument: {defense_response}\n\nEvaluate both arguments and determine who won the case. Provide reasons for your decision."
|
53 |
+
evaluation = ""
|
54 |
+
for message in client.chat_completion(
|
55 |
+
[{"role": "system", "content": "You are a legal expert evaluating the arguments presented by the prosecution and the defense."},
|
56 |
+
{"role": "user", "content": prompt}],
|
57 |
+
max_tokens=512,
|
58 |
+
stream=True,
|
59 |
+
temperature=0.6,
|
60 |
+
top_p=0.95,
|
61 |
+
):
|
62 |
+
token = message.choices[0].delta.content
|
63 |
+
if token is not None:
|
64 |
+
evaluation += token
|
65 |
+
return evaluation
|
|
|
66 |
|
67 |
+
def score_argument_from_outcome(outcome, argument):
|
68 |
+
# Simplified scoring based on keywords in the outcome
|
69 |
+
if "Prosecutor" in outcome:
|
70 |
+
prosecutor_score = outcome.count("Prosecutor") * 2
|
71 |
+
if "won" in outcome and "Prosecutor" in outcome:
|
72 |
+
prosecutor_score += 10
|
73 |
+
else:
|
74 |
+
prosecutor_score = 0
|
75 |
+
|
76 |
+
if "Defense" in outcome:
|
77 |
+
defense_score = outcome.count("Defense") * 2
|
78 |
+
if "won" in outcome and "Defense" in outcome:
|
79 |
+
defense_score += 10
|
80 |
+
else:
|
81 |
+
defense_score = 0
|
82 |
|
83 |
+
return prosecutor_score if "Prosecutor" in argument else defense_score
|
84 |
|
85 |
def color_code(score):
|
86 |
if score > 50:
|
|
|
178 |
response1 = response1[:max_length]
|
179 |
response2 = response2[:max_length]
|
180 |
|
181 |
+
outcome = generate_case_outcome(response1, response2)
|
182 |
+
|
183 |
+
score1 = score_argument_from_outcome(outcome, "Prosecutor")
|
184 |
+
score2 = score_argument_from_outcome(outcome, "Defense")
|
185 |
|
186 |
prosecutor_color = color_code(score1)
|
187 |
defense_color = color_code(score2)
|
|
|
189 |
prosecutor_score_color = f"<div class='score-box' style='background-color:{prosecutor_color};'>Score: {score1}</div>"
|
190 |
defense_score_color = f"<div class='score-box' style='background-color:{defense_color};'>Score: {score2}</div>"
|
191 |
|
|
|
|
|
192 |
return response1, response2, history1, history2, shared_history, outcome, prosecutor_score_color, defense_score_color
|
193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
def update_pdf_gallery(pdf_files):
|
195 |
return pdf_files
|
196 |
|