Spaces:
Paused
Paused
Add sandwich defense for hard challenge
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import huggingface_hub
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
@@ -179,16 +180,19 @@ def rows_to_text(rows: list[list[str]]) -> str:
|
|
179 |
return text
|
180 |
|
181 |
|
182 |
-
def get_summary(rows: list[list[str]]) -> str:
|
183 |
text = rows_to_text(rows)
|
184 |
prompt = text
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
client = openai.Client(api_key=openai_api_key)
|
186 |
completion = client.chat.completions.create(
|
187 |
model="gpt-4o-mini",
|
188 |
-
messages=
|
189 |
-
{"role": "system", "content": system_prompt},
|
190 |
-
{"role": "user", "content": prompt},
|
191 |
-
],
|
192 |
)
|
193 |
summary = completion.choices[0].message.content
|
194 |
return summary
|
@@ -207,7 +211,7 @@ def summarize_feedback(rows: list[list[str]], env: Env, username: str) -> str:
|
|
207 |
if env == Env.CHALLENGE_HARD:
|
208 |
summary = "-"
|
209 |
else:
|
210 |
-
summary = get_summary(rows)
|
211 |
|
212 |
add_review_db(env.value, user, feedback, summary)
|
213 |
|
|
|
1 |
+
from typing import Literal, Optional
|
2 |
import huggingface_hub
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
|
|
180 |
return text
|
181 |
|
182 |
|
183 |
+
def get_summary(rows: list[list[str]], difficulty: Optional[Literal["playground", "easy", "hard"]] = None) -> str:
|
184 |
text = rows_to_text(rows)
|
185 |
prompt = text
|
186 |
+
messages = [
|
187 |
+
{"role": "system", "content": system_prompt},
|
188 |
+
{"role": "user", "content": prompt},
|
189 |
+
]
|
190 |
+
if difficulty == "hard":
|
191 |
+
messages.append({"role": "user", "content":"Summarize the feedback"})
|
192 |
client = openai.Client(api_key=openai_api_key)
|
193 |
completion = client.chat.completions.create(
|
194 |
model="gpt-4o-mini",
|
195 |
+
messages=messages,
|
|
|
|
|
|
|
196 |
)
|
197 |
summary = completion.choices[0].message.content
|
198 |
return summary
|
|
|
211 |
if env == Env.CHALLENGE_HARD:
|
212 |
summary = "-"
|
213 |
else:
|
214 |
+
summary = get_summary(rows, "hard")
|
215 |
|
216 |
add_review_db(env.value, user, feedback, summary)
|
217 |
|