Spaces:
Runtime error
Runtime error
Commit
·
85e41fb
1
Parent(s):
0cba459
Add rating processing function to app.py for improved data handling
Browse files- app/app.py +10 -0
app/app.py
CHANGED
|
@@ -118,6 +118,15 @@ def _process_content(content) -> str | list[str]:
|
|
| 118 |
return content
|
| 119 |
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
def add_fake_like_data(
|
| 122 |
history: list, session_id: str, language: str, liked: bool = False
|
| 123 |
) -> None:
|
|
@@ -275,6 +284,7 @@ def submit_conversation(dataframe, session_id, language):
|
|
| 275 |
return (gr.Dataframe(value=None, interactive=False), [])
|
| 276 |
|
| 277 |
dataframe["content"] = dataframe["content"].apply(_process_content)
|
|
|
|
| 278 |
conversation = dataframe.to_dict(orient="records")
|
| 279 |
conversation_data = {
|
| 280 |
"conversation": conversation,
|
|
|
|
| 118 |
return content
|
| 119 |
|
| 120 |
|
| 121 |
+
def _process_rating(rating) -> int:
|
| 122 |
+
if isinstance(rating, str):
|
| 123 |
+
return 0
|
| 124 |
+
elif isinstance(rating, int):
|
| 125 |
+
return rating
|
| 126 |
+
else:
|
| 127 |
+
raise ValueError(f"Invalid rating: {rating}")
|
| 128 |
+
|
| 129 |
+
|
| 130 |
def add_fake_like_data(
|
| 131 |
history: list, session_id: str, language: str, liked: bool = False
|
| 132 |
) -> None:
|
|
|
|
| 284 |
return (gr.Dataframe(value=None, interactive=False), [])
|
| 285 |
|
| 286 |
dataframe["content"] = dataframe["content"].apply(_process_content)
|
| 287 |
+
dataframe["rating"] = dataframe["rating"].apply(_process_rating)
|
| 288 |
conversation = dataframe.to_dict(orient="records")
|
| 289 |
conversation_data = {
|
| 290 |
"conversation": conversation,
|