Update app.py
Browse files
app.py
CHANGED
|
@@ -21,22 +21,31 @@
|
|
| 21 |
# # The response to the POST request will be the output of the Gradio app.
|
| 22 |
# output = response.json()['text']
|
| 23 |
import gradio as gr
|
|
|
|
| 24 |
|
| 25 |
-
def my_function(name):
|
| 26 |
-
return "Hello " + name + "!!"
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
# Create a Gradio app.
|
| 30 |
app = gr.Interface(fn=my_function, inputs=['text'], outputs=['text'], allow_external_requests=True)
|
| 31 |
|
| 32 |
# Launch the Gradio app.
|
| 33 |
app.launch()
|
| 34 |
|
| 35 |
-
# Make a
|
| 36 |
data = {'text': 'This is a test.'}
|
| 37 |
-
response = requests.
|
| 38 |
|
| 39 |
-
# The response to the
|
| 40 |
output = response.json()['output']
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
|
|
|
| 21 |
# # The response to the POST request will be the output of the Gradio app.
|
| 22 |
# output = response.json()['text']
|
| 23 |
import gradio as gr
|
| 24 |
+
import requests
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
+
def my_function(name):
|
| 29 |
+
return "Hello " + name + "!!"
|
| 30 |
+
|
| 31 |
# Create a Gradio app.
|
| 32 |
app = gr.Interface(fn=my_function, inputs=['text'], outputs=['text'], allow_external_requests=True)
|
| 33 |
|
| 34 |
# Launch the Gradio app.
|
| 35 |
app.launch()
|
| 36 |
|
| 37 |
+
# Make a GET request to the URL of the Gradio app.
|
| 38 |
data = {'text': 'This is a test.'}
|
| 39 |
+
response = requests.get(app.url, data=data)
|
| 40 |
|
| 41 |
+
# The response to the GET request will be a JSON object.
|
| 42 |
output = response.json()['output']
|
| 43 |
|
| 44 |
+
# The input that you entered will be in the `input` key of the JSON object.
|
| 45 |
+
input = response.json()['input']
|
| 46 |
+
|
| 47 |
+
# Print the output and input.
|
| 48 |
+
print(output)
|
| 49 |
+
print(input)
|
| 50 |
+
|
| 51 |
|