Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -108,7 +108,7 @@ async def update_validation_space_on_answer(response, type, timestamp):
|
|
108 |
dataset_name = record.dataset.name
|
109 |
if not dataset_name.endswith("Responder"):
|
110 |
print(f"Ignoring event from non-answering dataset: {dataset_name}")
|
111 |
-
return
|
112 |
|
113 |
country = " ".join(dataset_name.split("-")[0].split(" ")[1:])
|
114 |
print(f"Processing response for country: {country}")
|
@@ -143,43 +143,25 @@ async def update_validation_space_on_answer(response, type, timestamp):
|
|
143 |
}
|
144 |
new_records.append(answer)
|
145 |
|
146 |
-
# Add the record to the validation space
|
147 |
validation_dataset.records.log(records=new_records)
|
148 |
print(f"Added new response to validation space for {country}")
|
149 |
|
150 |
except Exception as e:
|
151 |
print(f"Error in webhook handler: {e}")
|
152 |
-
# Store the error in the queue for display
|
153 |
incoming_events.put({"event": "error", "error": str(e)})
|
154 |
|
155 |
-
# Function to read the next event from the queue
|
156 |
def read_next_event():
|
157 |
if not incoming_events.empty():
|
158 |
return incoming_events.get()
|
159 |
return {}
|
160 |
|
161 |
-
# Create Gradio interface
|
162 |
with gr.Blocks() as demo:
|
163 |
argilla_server = client.http_client.base_url
|
164 |
-
gr.Markdown("## Argilla Webhooks -
|
165 |
-
gr.Markdown(f"""
|
166 |
-
This application listens for new responses in Argilla answering spaces and automatically
|
167 |
-
adds them to the corresponding validation spaces.
|
168 |
-
|
169 |
-
Connected to Argilla server: {argilla_server}
|
170 |
-
|
171 |
-
The webhook listens for:
|
172 |
-
- `response.created` events from datasets ending with `_responder_preguntas`
|
173 |
-
|
174 |
-
You can view the incoming events and any errors in the JSON component below.
|
175 |
-
""")
|
176 |
-
json_component = gr.JSON(label="Incoming events and errors:", value={})
|
177 |
gr.Timer(1, active=True).tick(read_next_event, outputs=json_component)
|
178 |
|
179 |
-
# Mount the Gradio app to the FastAPI server
|
180 |
gr.mount_gradio_app(server, demo, path="/")
|
181 |
|
182 |
-
# Start the FastAPI server
|
183 |
if __name__ == "__main__":
|
184 |
import uvicorn
|
185 |
uvicorn.run(server, host="0.0.0.0", port=7860)
|
|
|
108 |
dataset_name = record.dataset.name
|
109 |
if not dataset_name.endswith("Responder"):
|
110 |
print(f"Ignoring event from non-answering dataset: {dataset_name}")
|
111 |
+
return
|
112 |
|
113 |
country = " ".join(dataset_name.split("-")[0].split(" ")[1:])
|
114 |
print(f"Processing response for country: {country}")
|
|
|
143 |
}
|
144 |
new_records.append(answer)
|
145 |
|
|
|
146 |
validation_dataset.records.log(records=new_records)
|
147 |
print(f"Added new response to validation space for {country}")
|
148 |
|
149 |
except Exception as e:
|
150 |
print(f"Error in webhook handler: {e}")
|
|
|
151 |
incoming_events.put({"event": "error", "error": str(e)})
|
152 |
|
|
|
153 |
def read_next_event():
|
154 |
if not incoming_events.empty():
|
155 |
return incoming_events.get()
|
156 |
return {}
|
157 |
|
|
|
158 |
with gr.Blocks() as demo:
|
159 |
argilla_server = client.http_client.base_url
|
160 |
+
gr.Markdown("## Argilla Webhooks - Top Secret")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
gr.Timer(1, active=True).tick(read_next_event, outputs=json_component)
|
162 |
|
|
|
163 |
gr.mount_gradio_app(server, demo, path="/")
|
164 |
|
|
|
165 |
if __name__ == "__main__":
|
166 |
import uvicorn
|
167 |
uvicorn.run(server, host="0.0.0.0", port=7860)
|