Spaces:
Running
Running
Update app.py
Browse files
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(
|
| 15 |
-
#
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
"data": [input_data],
|
| 19 |
# You can add other kwargs to the payload here if needed by the specific API
|
| 20 |
-
|
| 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="
|
| 30 |
-
text_output = gr.Textbox(label="Response
|
| 31 |
-
submit_btn = gr.Button("
|
| 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()
|