Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
import json, os, vertexai
|
3 |
|
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 |
|
11 |
config = {
|
12 |
"max_output_tokens": 800,
|
@@ -32,12 +31,6 @@ vertexai.init(project = project,
|
|
32 |
from vertexai.preview.generative_models import GenerativeModel
|
33 |
generation_model = GenerativeModel(config["model"])
|
34 |
|
35 |
-
def wandb_log(prompt, completion):
|
36 |
-
wandb.login(key = wandb_api_key)
|
37 |
-
wandb.init(project = "vertex-ai-llm", config = config)
|
38 |
-
wandb.log({"prompt": str(prompt), "completion": str(completion)})
|
39 |
-
wandb.finish()
|
40 |
-
|
41 |
def invoke(prompt):
|
42 |
if (prompt == ""):
|
43 |
raise gr.Error("Prompt is required.")
|
@@ -59,13 +52,10 @@ def invoke(prompt):
|
|
59 |
completion = e
|
60 |
|
61 |
raise gr.Error(e)
|
62 |
-
finally:
|
63 |
-
wandb_log(prompt, completion)
|
64 |
|
65 |
return completion
|
66 |
|
67 |
-
description = "
|
68 |
-
with Gemini Pro model. Evaluation via <a href='https://wandb.ai/bstraehle'>Weights & Biases</a>."""
|
69 |
|
70 |
gr.close_all()
|
71 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import json, os, vertexai
|
3 |
|
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 |
|
10 |
config = {
|
11 |
"max_output_tokens": 800,
|
|
|
31 |
from vertexai.preview.generative_models import GenerativeModel
|
32 |
generation_model = GenerativeModel(config["model"])
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
def invoke(prompt):
|
35 |
if (prompt == ""):
|
36 |
raise gr.Error("Prompt is required.")
|
|
|
52 |
completion = e
|
53 |
|
54 |
raise gr.Error(e)
|
|
|
|
|
55 |
|
56 |
return completion
|
57 |
|
58 |
+
description = "<a href='https://www.gradio.app/'>Gradio</a> UI using the <a href='https://cloud.google.com/vertex-ai'>Google Vertex AI</a> API with Gemini Pro model."
|
|
|
59 |
|
60 |
gr.close_all()
|
61 |
|