added persistence of voting
Browse files- .gitignore +1 -0
- README.md +0 -1
- app.py +17 -21
- dga.csv → connection_v1b.csv +0 -0
- connections.csv +17 -0
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
.venv
|
|
|
|
|
|
| 1 |
.venv
|
| 2 |
+
.gradio
|
README.md
CHANGED
|
@@ -4,7 +4,6 @@ emoji: "📝"
|
|
| 4 |
colorFrom: "blue"
|
| 5 |
colorTo: "purple"
|
| 6 |
sdk: "gradio"
|
| 7 |
-
sdk_version: "4.0.0"
|
| 8 |
app_file: "app.py"
|
| 9 |
pinned: false
|
| 10 |
license: "mit"
|
|
|
|
| 4 |
colorFrom: "blue"
|
| 5 |
colorTo: "purple"
|
| 6 |
sdk: "gradio"
|
|
|
|
| 7 |
app_file: "app.py"
|
| 8 |
pinned: false
|
| 9 |
license: "mit"
|
app.py
CHANGED
|
@@ -2,16 +2,8 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
# Load the CSV data
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
("⼆⽉ (February)", "充满了冰 (Filled with ice)", "February is often associated with winter, which is filled with ice, reinforcing the theme of coldness and stagnation."),
|
| 8 |
-
("⼆⽉ (February)", "在早晨的寒冷中 (In the cold of the morning)", "February's coldness extends to the morning, symbolizing a harsh, unyielding reality."),
|
| 9 |
-
("夜正趋于完美 (The night is becoming perfect)", "死亡的乐器 (The instrument of death)", "The perfection of the night could symbolize the finality of death, as night often represents the end of a cycle."),
|
| 10 |
-
("夜正趋于完美 (The night is becoming perfect)", "⽕焰失⾎ (The flame loses blood)", "The perfect night contrasts with the dying flame, suggesting the extinguishing of life or passion."),
|
| 11 |
-
# Add all other rows here...
|
| 12 |
-
]
|
| 13 |
-
|
| 14 |
-
df = pd.DataFrame(data, columns=["Symbol 1", "Symbol 2", "Reasoning"])
|
| 15 |
|
| 16 |
poem = """
|
| 17 |
⼆⽉
|
|
@@ -34,19 +26,23 @@ poem = """
|
|
| 34 |
某些动作与阴影
|
| 35 |
"""
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
def display_row(index):
|
| 40 |
if 0 <= index < len(df):
|
| 41 |
row = df.iloc[index]
|
| 42 |
-
return poem, row["Symbol 1"], row["Symbol 2"], row["Reasoning"]
|
| 43 |
-
return poem, "", "", ""
|
| 44 |
|
| 45 |
def flag_relationship(index, feedback):
|
| 46 |
if 0 <= index < len(df):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
with gr.Blocks() as app:
|
| 52 |
gr.Markdown("## Poem and Symbolic Relationships")
|
|
@@ -55,17 +51,17 @@ with gr.Blocks() as app:
|
|
| 55 |
symbol1 = gr.Textbox(label="Symbol 1")
|
| 56 |
symbol2 = gr.Textbox(label="Symbol 2")
|
| 57 |
reasoning = gr.Textbox(label="Reasoning")
|
|
|
|
| 58 |
|
| 59 |
index_slider = gr.Slider(0, len(df) - 1, step=1, label="Select Row Index", value=0)
|
| 60 |
-
index_slider.change(display_row, index_slider, [poem_display, symbol1, symbol2, reasoning])
|
| 61 |
|
| 62 |
feedback_output = gr.Textbox(label="Feedback Status")
|
| 63 |
with gr.Row():
|
| 64 |
thumbs_up = gr.Button("👍")
|
| 65 |
thumbs_down = gr.Button("👎")
|
| 66 |
|
| 67 |
-
thumbs_up.click(lambda index: flag_relationship(index, "up"), index_slider, feedback_output)
|
| 68 |
-
thumbs_down.click(lambda index: flag_relationship(index, "down"), index_slider, feedback_output)
|
| 69 |
-
|
| 70 |
|
| 71 |
-
app.launch(
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
# Load the CSV data
|
| 5 |
+
df = pd.read_csv("connections.csv")
|
| 6 |
+
df["Score"] = "0/0" # Initialize score as 0/0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
poem = """
|
| 9 |
⼆⽉
|
|
|
|
| 26 |
某些动作与阴影
|
| 27 |
"""
|
| 28 |
|
| 29 |
+
votes = {index: {"up": 0, "down": 0} for index in range(len(df))}
|
| 30 |
|
| 31 |
def display_row(index):
|
| 32 |
if 0 <= index < len(df):
|
| 33 |
row = df.iloc[index]
|
| 34 |
+
return poem, row["Symbol 1"], row["Symbol 2"], row["Reasoning"], row["Score"]
|
| 35 |
+
return poem, "", "", "", ""
|
| 36 |
|
| 37 |
def flag_relationship(index, feedback):
|
| 38 |
if 0 <= index < len(df):
|
| 39 |
+
votes[index][feedback] += 1
|
| 40 |
+
up_votes = votes[index]["up"]
|
| 41 |
+
total_votes = up_votes + votes[index]["down"]
|
| 42 |
+
df.at[index, "Score"] = f"{up_votes}/{total_votes}"
|
| 43 |
+
df.to_csv("connections.csv", index=False) # Save updated scores to CSV
|
| 44 |
+
return f"Feedback received: {'👍' if feedback == 'up' else '👎'} for row {index}", df.at[index, "Score"]
|
| 45 |
+
return "Invalid index.", "0/0"
|
| 46 |
|
| 47 |
with gr.Blocks() as app:
|
| 48 |
gr.Markdown("## Poem and Symbolic Relationships")
|
|
|
|
| 51 |
symbol1 = gr.Textbox(label="Symbol 1")
|
| 52 |
symbol2 = gr.Textbox(label="Symbol 2")
|
| 53 |
reasoning = gr.Textbox(label="Reasoning")
|
| 54 |
+
score_display = gr.Textbox(label="Score")
|
| 55 |
|
| 56 |
index_slider = gr.Slider(0, len(df) - 1, step=1, label="Select Row Index", value=0)
|
| 57 |
+
index_slider.change(display_row, index_slider, [poem_display, symbol1, symbol2, reasoning, score_display])
|
| 58 |
|
| 59 |
feedback_output = gr.Textbox(label="Feedback Status")
|
| 60 |
with gr.Row():
|
| 61 |
thumbs_up = gr.Button("👍")
|
| 62 |
thumbs_down = gr.Button("👎")
|
| 63 |
|
| 64 |
+
thumbs_up.click(lambda index: flag_relationship(index, "up"), index_slider, [feedback_output, score_display])
|
| 65 |
+
thumbs_down.click(lambda index: flag_relationship(index, "down"), index_slider, [feedback_output, score_display])
|
|
|
|
| 66 |
|
| 67 |
+
app.launch()
|
dga.csv → connection_v1b.csv
RENAMED
|
File without changes
|
connections.csv
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Symbol 1,Symbol 2,Reasoning,Score
|
| 2 |
+
⼆⽉ (February),书中的⼆⽉ (February in the book),Layered temporality—both real and textual,0/0
|
| 3 |
+
夜正趋于完美 (The night is approaching perfection),死亡的乐器 (Instruments of death),Night symbolizes death or endings,2/3
|
| 4 |
+
我在语⾔中漂流 (I am drifting in language),⽇⼦的裂缝上 (On the cracks of days),Language navigates fractures in time or existence,0/0
|
| 5 |
+
死亡的乐器 (Instruments of death),充满了冰 (Filled with ice),"Ice symbolizes coldness, stillness, and preservation",1/2
|
| 6 |
+
充满了冰 (Filled with ice),⽔变苦 (Water turns bitter),"Transformations of states (solid to liquid, sweet to bitter)",0/0
|
| 7 |
+
谁在⽇⼦的裂缝上歌唱 (Who is singing on the cracks of days),⽕焰失⾎ (Flames lose blood),"Transformations or losses (sound to silence, fire to ash)",0/0
|
| 8 |
+
⽔变苦 (Water turns bitter),⼭猫般奔向星星 (Like a wildcat running toward the stars),"Transformations (water to bitterness, earthbound to celestial)",0/0
|
| 9 |
+
⽕焰失⾎ (Flames lose blood),必有⼀种形式 (There must be a form),Transformation or structure emerging from chaos,0/0
|
| 10 |
+
⼭猫般奔向星星 (Like a wildcat running toward the stars),才能做梦 (To be able to dream),Striving toward something beyond immediate reality,0/0
|
| 11 |
+
必有⼀种形式 (There must be a form),在早晨的寒冷中 (In the cold of morning),Emergence of clarity or structure from chaos or discomfort,0/0
|
| 12 |
+
在早晨的寒冷中 (In the cold of morning),⼀只觉醒的⻦ (An awakened bird),Awakening or realization,0/0
|
| 13 |
+
⼀只觉醒的⻦ (An awakened bird),更接近真理 (Closer to truth),Pursuit of higher understanding,0/0
|
| 14 |
+
更接近真理 (Closer to truth),⽽我和我的诗⼀起下沉 (While I and my poetry sink together),Tension between aspiration and reality,0/0
|
| 15 |
+
⽽我和我的诗⼀起下沉 (While I and my poetry sink together),书中的⼆⽉ (February in the book),Interplay between reality and representation,0/0
|
| 16 |
+
书中的⼆⽉ (February in the book),某些动作与阴影 (Certain movements and shadows),Interplay of action and obscurity,0/0
|
| 17 |
+
某些动作与阴影 (Certain movements and shadows),夜正趋于完美 (The night is approaching perfection),"Interplay of light and darkness, action and stillness",0/0
|