Francisco Aranda commited on
Commit
16eaf19
1 Parent(s): 30c85ad

chore: Configure Gradio env

Browse files
Files changed (4) hide show
  1. README.md +15 -21
  2. main.py → app.py +7 -10
  3. requirements.txt +2 -2
  4. start.sh +0 -2
README.md CHANGED
@@ -1,40 +1,34 @@
1
  ---
2
  title: Argilla Webhooks
3
- emoji: 🐠
4
- colorFrom: indigo
5
- colorTo: indigo
6
- sdk: docker
 
 
7
  pinned: false
8
  ---
9
 
10
  ## Description
11
 
12
- This is a basic webhook example to show how to setup webhook listeners using the argilla SDK
 
13
 
14
  ## Running the app
15
 
16
- 1. Start argilla server and argilla worker
 
17
  ```bash
18
- pdm server start
19
- pdm worker
20
  ```
21
 
22
- 2. Add the `localhost.org` alias in the `/etc/hosts` file to comply with the Top Level Domain URL requirement.
23
- ```
24
- ##
25
- # Host Database
26
- #
27
- # localhost is used to configure the loopback interface
28
- # when the system is booting. Do not change this entry.
29
- ##
30
- 127.0.0.1 localhost localhost.org
31
- ```
32
 
33
- 2. Start the app
34
  ```bash
35
- uvicorn main:server
36
  ```
37
 
38
  ## Testing the app
39
 
40
- You can see in se server logs traces when working with dataset, records and responses in the argilla server
 
1
  ---
2
  title: Argilla Webhooks
3
+ emoji: 🦀
4
+ colorFrom: pink
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
  ## Description
13
 
14
+ This space is a basic server webhooks example to show how to set up webhook listeners using the argilla SDK.
15
+
16
 
17
  ## Running the app
18
 
19
+ First create an HF space running the argilla server. Once the server is up and running, you must define the following environment variables:
20
+
21
  ```bash
22
+ export ARGILLA_API_KEY=<your_api_key>
23
+ export ARGILLA_API_URL=<your_api_url>
24
  ```
25
 
26
+ Now, you can run the app just running the following command:
 
 
 
 
 
 
 
 
 
27
 
 
28
  ```bash
29
+ python app.py
30
  ```
31
 
32
  ## Testing the app
33
 
34
+ Open the gradio application on a browser (http://localhost:7860). You can see incoming events from the argilla server.
main.py → app.py RENAMED
@@ -10,18 +10,13 @@ client = rg.Argilla()
10
  server = rg.get_webhook_server()
11
  incoming_events = Queue()
12
 
13
- # The default webhook server URL is set to http://127.0.0.1:8000
14
- # This value is important since the webhook server URL is used to create the webhook URLs
15
- # When the SPACE_HOST environment variable is set, the default webhook server URL is set to https://SPACE_HOST value
16
- # If the FastAPI app is running on a different URL, the WEBHOOK_SERVER_URL environment variable should be set
17
- default_webhook_server_url = os.getenv("WEBHOOK_SERVER_URL")
18
- if default_webhook_server_url is None and "SPACE_HOST" in os.environ:
19
- # We set it to the default gradio server URL
20
- os.environ["WEBHOOK_SERVER_URL"] = "http://127.0.0.1:7860"
21
-
22
-
23
  # Set up the webhook listeners
24
 
 
 
 
 
 
25
  # Create a webhook for record events
26
  @rg.webhook_listener(events=["record.created", "record.updated", "record.deleted", "record.completed"])
27
  async def record_events(record: rg.Record, type: str, timestamp: datetime):
@@ -60,3 +55,5 @@ with gr.Blocks() as demo:
60
  gr.Timer(1, active=True).tick(read_next_event, outputs=json_component)
61
 
62
  gr.mount_gradio_app(server, demo, path="/")
 
 
 
10
  server = rg.get_webhook_server()
11
  incoming_events = Queue()
12
 
 
 
 
 
 
 
 
 
 
 
13
  # Set up the webhook listeners
14
 
15
+ # Delete all existing webhooks
16
+ for webhook in client.webhooks:
17
+ print(f"Deleting webhook: {webhook.url}")
18
+ webhook.delete()
19
+
20
  # Create a webhook for record events
21
  @rg.webhook_listener(events=["record.created", "record.updated", "record.deleted", "record.completed"])
22
  async def record_events(record: rg.Record, type: str, timestamp: datetime):
 
55
  gr.Timer(1, active=True).tick(read_next_event, outputs=json_component)
56
 
57
  gr.mount_gradio_app(server, demo, path="/")
58
+
59
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- gradio
2
- argilla @ git+https://github.com/argilla-io/argilla.git@feat/argilla/working-with-webhooks#subdirectory=argilla
 
1
+ gradio ~= 4.44.0
2
+ argilla @ git+https://github.com/argilla-io/argilla.git@releases/2.5.0#subdirectory=argilla
start.sh DELETED
@@ -1,2 +0,0 @@
1
- uvicorn main:server --host 0.0.0.0 --port 7860
2
-