marcmaxmeister commited on
Commit
82f03fd
·
verified ·
1 Parent(s): 0409241

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import os
2
  import requests
 
3
 
4
  # Access the secret environment variable
5
  space_token = os.environ.get('api_key')
6
- api_url = "https://givingtuesday-annotated-990-data.hf.space"
7
  headers = {
8
  "Authorization": f"Bearer {space_token}",
9
  "Content-Type": "application/json"
@@ -11,24 +12,22 @@ headers = {
11
 
12
 
13
 
14
- def call_private_api(input_data):
15
- # The payload structure depends on the private API's expected input
16
- # 'data' should be a list matching the input components of the target space
17
- payload = {
18
- "data": [input_data],
19
  # You can add other kwargs to the payload here if needed by the specific API
20
- "kwargs": {"some_param": "some_value"}
21
- }
22
-
23
- response = requests.post(api_url, headers=headers, data=json.dumps(payload))
24
  return response.json()
25
 
26
  import gradio as gr
27
  # Example usage within a Gradio interface in the public space
28
  with gr.Blocks() as demo:
29
- text_input = gr.Textbox(label="Enter input for private API")
30
- text_output = gr.Textbox(label="Response from private API")
31
- submit_btn = gr.Button("Call API")
32
  submit_btn.click(fn=call_private_api, inputs=text_input, outputs=text_output)
33
 
34
  demo.launch()
 
1
  import os
2
  import requests
3
+ import json
4
 
5
  # Access the secret environment variable
6
  space_token = os.environ.get('api_key')
7
+ api_url = "https://givingtuesday-annotated-990-data.hf.space/eins"
8
  headers = {
9
  "Authorization": f"Bearer {space_token}",
10
  "Content-Type": "application/json"
 
12
 
13
 
14
 
15
+ def call_private_api(**kwargs):
16
+ # 'kwargs' should be a dict matching the input components of the target space
17
+ #payload = {
18
+ # "data": [input_data],
 
19
  # You can add other kwargs to the payload here if needed by the specific API
20
+ # "kwargs": {"some_param": "some_value"}
21
+ #}
22
+ response = requests.post(api_url, headers=headers, json=kwargs)
 
23
  return response.json()
24
 
25
  import gradio as gr
26
  # Example usage within a Gradio interface in the public space
27
  with gr.Blocks() as demo:
28
+ text_input = gr.Textbox(label="Input")
29
+ text_output = gr.Textbox(label="Response")
30
+ submit_btn = gr.Button("Get eins")
31
  submit_btn.click(fn=call_private_api, inputs=text_input, outputs=text_output)
32
 
33
  demo.launch()