Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import json, os, vertexai, wandb
|
|
4 |
from dotenv import load_dotenv, find_dotenv
|
5 |
_ = load_dotenv(find_dotenv())
|
6 |
|
7 |
-
credentials = os.environ["CREDENTIALS"]
|
8 |
project = os.environ["PROJECT"]
|
9 |
wandb_api_key = os.environ["WANDB_API_KEY"]
|
10 |
|
@@ -16,29 +16,37 @@ wandb.login(key = wandb_api_key)
|
|
16 |
wandb.init(project = "vertext-ai-txt", config = config)
|
17 |
config = wandb.config
|
18 |
|
19 |
-
credentials = json.loads(credentials)
|
20 |
|
21 |
from google.oauth2 import service_account
|
22 |
-
credentials = service_account.Credentials.from_service_account_info(credentials)
|
23 |
|
24 |
-
if credentials.expired:
|
25 |
-
credentials.refresh(Request())
|
26 |
|
27 |
-
vertexai.init(project = project,
|
28 |
-
location = "us-central1",
|
29 |
-
credentials = credentials)
|
30 |
|
31 |
from vertexai.language_models import TextGenerationModel
|
32 |
generation_model = TextGenerationModel.from_pretrained("text-bison@001")
|
33 |
|
34 |
-
def invoke(prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
completion = generation_model.predict(prompt = prompt).text
|
36 |
wandb.log({"prompt": prompt, "completion": completion})
|
37 |
return completion
|
38 |
|
39 |
gr.close_all()
|
40 |
demo = gr.Interface(fn=invoke,
|
41 |
-
inputs = [gr.Textbox(label = "Prompt", lines = 1)],
|
42 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
43 |
title = "Generative AI - Language",
|
44 |
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")
|
|
|
4 |
from dotenv import load_dotenv, find_dotenv
|
5 |
_ = load_dotenv(find_dotenv())
|
6 |
|
7 |
+
//credentials = os.environ["CREDENTIALS"]
|
8 |
project = os.environ["PROJECT"]
|
9 |
wandb_api_key = os.environ["WANDB_API_KEY"]
|
10 |
|
|
|
16 |
wandb.init(project = "vertext-ai-txt", config = config)
|
17 |
config = wandb.config
|
18 |
|
19 |
+
//credentials = json.loads(credentials)
|
20 |
|
21 |
from google.oauth2 import service_account
|
22 |
+
//credentials = service_account.Credentials.from_service_account_info(credentials)
|
23 |
|
24 |
+
//if credentials.expired:
|
25 |
+
// credentials.refresh(Request())
|
26 |
|
27 |
+
//vertexai.init(project = project,
|
28 |
+
// location = "us-central1",
|
29 |
+
// credentials = credentials)
|
30 |
|
31 |
from vertexai.language_models import TextGenerationModel
|
32 |
generation_model = TextGenerationModel.from_pretrained("text-bison@001")
|
33 |
|
34 |
+
def invoke(prompt, credentials):
|
35 |
+
//
|
36 |
+
credentials = service_account.Credentials.from_service_account_info(credentials)
|
37 |
+
if credentials.expired:
|
38 |
+
credentials.refresh(Request())
|
39 |
+
vertexai.init(project = project,
|
40 |
+
location = "us-central1",
|
41 |
+
credentials = credentials)
|
42 |
+
//
|
43 |
completion = generation_model.predict(prompt = prompt).text
|
44 |
wandb.log({"prompt": prompt, "completion": completion})
|
45 |
return completion
|
46 |
|
47 |
gr.close_all()
|
48 |
demo = gr.Interface(fn=invoke,
|
49 |
+
inputs = [gr.Textbox(label = "Prompt", lines = 1), gr.Textbox(label = "Credentials", lines = 1)],
|
50 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
51 |
title = "Generative AI - Language",
|
52 |
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")
|