bstraehle commited on
Commit
80d3afc
·
1 Parent(s): d03e9ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import vertexai, os
3
+
4
+ from dotenv import load_dotenv, find_dotenv
5
+ _ = load_dotenv(find_dotenv())
6
+
7
+ credentials =
8
+ project =
9
+ openai_api_key = os.environ['OPENAI_API_KEY']
10
+
11
+ def invoke(prompt):
12
+ response = openai.ChatCompletion.create(
13
+ model = "gpt-3.5-turbo",
14
+ messages = [{"role": "user", "content": prompt}],
15
+ temperature = 0,
16
+ max_tokens = 500,
17
+ )
18
+ return response.choices[0].message["content"]
19
+
20
+ gr.close_all()
21
+ demo = gr.Interface(fn=invoke,
22
+ inputs = [gr.Textbox(label = "Prompt", lines = 1)],
23
+ outputs = [gr.Textbox(label = "Completion", lines = 1)],
24
+ title = "Generative AI - Text",
25
+ description = "<a href='https://www.gradio.app/'>Gradio</a> UI using <a href='https://cloud.google.com/vertex-ai?hl=en/'>Google Vertex AI</a> API with Bison foundation model")
26
+ demo.launch()