Gervas Mshamu commited on
Commit
801981e
1 Parent(s): 1603531

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ """
5
+ Get your API key from https://makersuite.google.com/app/apikey
6
+ """
7
+
8
+ API_KEY = "AIzaSyApI6-GxkTMrpAc4P4wdy37jn_6SwHTTtw" #Enter your API key
9
+ API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key={API_KEY}".format(API_KEY=API_KEY)
10
+
11
+
12
+ def processor(input):
13
+
14
+ payload = {
15
+ "contents":[
16
+ {
17
+ "parts":[
18
+ {
19
+ "text": "Make a joke from the following statement," + input
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
25
+
26
+ response = requests.post(API_URL,json=payload)
27
+
28
+ return response.json()['candidates'][0]['content']['parts'][0]['text']
29
+
30
+ """
31
+ We have used the gradio framework,
32
+ Full documentation visit https://www.gradio.app/
33
+ """
34
+
35
+ inputs = gr.Textbox(lines=2, placeholder="Eg: Tell me a coffee shop joke",label="Input Text")
36
+ outputs = gr.Textbox(label="Joke(s) Generated")
37
+ title = "Joke Generator App"
38
+
39
+ app = gr.Interface(fn=processor,inputs=inputs,outputs="text",title=title)
40
+ app.launch(share=True)