siya02 commited on
Commit
a8c2ec4
·
1 Parent(s): 6f63bac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -18
app.py CHANGED
@@ -20,32 +20,57 @@
20
 
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
 
 
20
 
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
+ import gradio
52
+
53
+ # Create a Gradio app.
54
+ interface = gradio.Interface(
55
+ fn=predict,
56
+ inputs=[gradio.inputs.Textbox()],
57
+ outputs=[gradio.outputs.Text()],
58
+ )
59
 
60
+ # Add a `predict()` method to the Gradio app.
61
+ def predict(text):
62
+ # Use the model to predict the output.
63
+ output = model(text)
64
 
65
+ # Return the output.
66
+ return output
67
 
68
+ # Save the Gradio app.
69
+ interface.save("my_app")
70
 
71
+ # Deploy the Gradio app.
72
+ interface.deploy()
 
73
 
74
+ # Create a post API endpoint.
75
+ interface.create_post_api()
76