Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -84,7 +84,13 @@ def translate_sentence(sentence, verbose=False):
|
|
84 |
# ----------------------------------------------------------------------------------------------------------------------------------------
|
85 |
# Gradio app
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def update_history_with_status(english, french, history, status):
|
89 |
history.append((english, french, status))
|
90 |
history_text = "\n".join([f"{inp} ----> {out} ({status})" for inp, out, status in history])
|
@@ -98,22 +104,43 @@ def revert_last_action(history):
|
|
98 |
# Update history block text
|
99 |
history_text = "\n".join([f"{inp} ----> {out} ({status})" for inp, out, status in history])
|
100 |
|
101 |
-
# Revert last row in the
|
102 |
if row_indices:
|
103 |
last_index = row_indices.pop()
|
104 |
-
# Remove the last row from the
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
df.to_csv(csv_file, index=False)
|
112 |
-
# print('dumped the df to csv')
|
113 |
return history_text, history
|
114 |
|
115 |
-
#
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# Define the Gradio interface
|
119 |
with gr.Blocks(theme='gstaff/sketch') as demo:
|
@@ -133,11 +160,6 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
133 |
flag_button = gr.Button(value="Flag", variant="secondary")
|
134 |
revert_button = gr.Button(value="Revert", variant="secondary")
|
135 |
|
136 |
-
# This needs to be called at some point prior to the first call to flagging.callback.flag()
|
137 |
-
# flagging_callback.setup([english, french, corrected_french, "IsFlagged"], "flagged_translations")
|
138 |
-
flagging_callback.setup([english, french, corrected_french, flagged_successful], "flagged_translations")
|
139 |
-
|
140 |
-
|
141 |
examples = gr.Examples(examples=[
|
142 |
"paris is relaxing during december but it is usually chilly in july",
|
143 |
"She is driving the truck"],
|
@@ -149,27 +171,6 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
149 |
|
150 |
# Track the row indices in the CSVLogger
|
151 |
row_indices = []
|
152 |
-
def flag_action(english, french, corrected_french, flagged_successful, history):
|
153 |
-
data = [english, french, corrected_french, flagged_successful]
|
154 |
-
# Add the IsFlagged column with value True
|
155 |
-
flagged_value = flagged_successful if flagged_successful else "Flagged"
|
156 |
-
print(f"Flag Action - flagged_successful: {flagged_value}")
|
157 |
-
print(f"flagged_successful object: {flagged_successful}")
|
158 |
-
|
159 |
-
index = flagging_callback.flag(data)
|
160 |
-
row_indices.append(index)
|
161 |
-
return update_history_with_status(english, french, history, "Flagged")
|
162 |
-
|
163 |
-
def accept_action(english, french, hidden_text, flagged_successful, history):
|
164 |
-
data = [english, french, hidden_text, flagged_successful]
|
165 |
-
# Add the IsFlagged column with value False
|
166 |
-
# Extract value from flagged_successful
|
167 |
-
flagged_value = flagged_successful if flagged_successful else "Accepted"
|
168 |
-
print(f"Accept Action - flagged_successful: {flagged_value}")
|
169 |
-
print(f"flagged_successful object: {flagged_successful}")
|
170 |
-
index = flagging_callback.flag(data)
|
171 |
-
row_indices.append(index)
|
172 |
-
return update_history_with_status(english, french, history, "Accepted")
|
173 |
|
174 |
gr.on(
|
175 |
triggers=[english.submit, Translate_button.click],
|
@@ -192,7 +193,6 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
192 |
outputs=[history_block, history],
|
193 |
)
|
194 |
|
195 |
-
|
196 |
gr.on(
|
197 |
triggers=[accept_button.click],
|
198 |
fn=lambda: gr.Textbox(value="Accepted", visible=True),
|
@@ -214,5 +214,4 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
214 |
outputs=flagged_successful,
|
215 |
)
|
216 |
|
217 |
-
demo.launch(share=True, auth=('username', 'Zaka_module7'),
|
218 |
-
auth_message="Check your <strong>Login details</strong> sent to your <i>email</i>")#, debug=True)
|
|
|
84 |
# ----------------------------------------------------------------------------------------------------------------------------------------
|
85 |
# Gradio app
|
86 |
|
87 |
+
from datasets import load_dataset, Dataset, DatasetDict
|
88 |
+
|
89 |
+
# Load the private dataset from Hugging Face
|
90 |
+
def load_hf_dataset():
|
91 |
+
dataset = load_dataset("your_hf_username/translation_log", split="train")
|
92 |
+
return dataset
|
93 |
+
|
94 |
def update_history_with_status(english, french, history, status):
|
95 |
history.append((english, french, status))
|
96 |
history_text = "\n".join([f"{inp} ----> {out} ({status})" for inp, out, status in history])
|
|
|
104 |
# Update history block text
|
105 |
history_text = "\n".join([f"{inp} ----> {out} ({status})" for inp, out, status in history])
|
106 |
|
107 |
+
# Revert last row in the dataset
|
108 |
if row_indices:
|
109 |
last_index = row_indices.pop()
|
110 |
+
# Remove the last row from the dataset
|
111 |
+
dataset = load_hf_dataset()
|
112 |
+
df = dataset.to_pandas()
|
113 |
+
df = df.drop(last_index).reset_index(drop=True)
|
114 |
+
updated_dataset = Dataset.from_pandas(df)
|
115 |
+
dataset_dict = DatasetDict({"train": updated_dataset})
|
116 |
+
dataset_dict.push_to_hub("your_hf_username/translation_log")
|
|
|
|
|
117 |
return history_text, history
|
118 |
|
119 |
+
# Function to flag data
|
120 |
+
def flag_action(english, french, corrected_french, flagged_successful, history):
|
121 |
+
data = {"english": english, "french": french, "corrected_french": corrected_french, "status": flagged_successful}
|
122 |
+
dataset = load_hf_dataset()
|
123 |
+
df = dataset.to_pandas()
|
124 |
+
df = df.append(data, ignore_index=True)
|
125 |
+
updated_dataset = Dataset.from_pandas(df)
|
126 |
+
dataset_dict = DatasetDict({"train": updated_dataset})
|
127 |
+
dataset_dict.push_to_hub("your_hf_username/translation_log")
|
128 |
+
index = len(df) - 1
|
129 |
+
row_indices.append(index)
|
130 |
+
return update_history_with_status(english, french, history, "Flagged")
|
131 |
+
|
132 |
+
# Function to accept data
|
133 |
+
def accept_action(english, french, hidden_text, flagged_successful, history):
|
134 |
+
data = {"english": english, "french": french, "corrected_french": hidden_text, "status": flagged_successful}
|
135 |
+
dataset = load_hf_dataset()
|
136 |
+
df = dataset.to_pandas()
|
137 |
+
df = df.append(data, ignore_index=True)
|
138 |
+
updated_dataset = Dataset.from_pandas(df)
|
139 |
+
dataset_dict = DatasetDict({"train": updated_dataset})
|
140 |
+
dataset_dict.push_to_hub("your_hf_username/translation_log")
|
141 |
+
index = len(df) - 1
|
142 |
+
row_indices.append(index)
|
143 |
+
return update_history_with_status(english, french, history, "Accepted")
|
144 |
|
145 |
# Define the Gradio interface
|
146 |
with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
|
160 |
flag_button = gr.Button(value="Flag", variant="secondary")
|
161 |
revert_button = gr.Button(value="Revert", variant="secondary")
|
162 |
|
|
|
|
|
|
|
|
|
|
|
163 |
examples = gr.Examples(examples=[
|
164 |
"paris is relaxing during december but it is usually chilly in july",
|
165 |
"She is driving the truck"],
|
|
|
171 |
|
172 |
# Track the row indices in the CSVLogger
|
173 |
row_indices = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
gr.on(
|
176 |
triggers=[english.submit, Translate_button.click],
|
|
|
193 |
outputs=[history_block, history],
|
194 |
)
|
195 |
|
|
|
196 |
gr.on(
|
197 |
triggers=[accept_button.click],
|
198 |
fn=lambda: gr.Textbox(value="Accepted", visible=True),
|
|
|
214 |
outputs=flagged_successful,
|
215 |
)
|
216 |
|
217 |
+
demo.launch(share=True, auth=('username', 'Zaka_module7'), auth_message="Check your <strong>Login details</strong> sent to your <i>email</i>")
|
|