Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,6 @@ wandb_api_key = os.environ["WANDB_API_KEY"]
|
|
10 |
|
11 |
config = {
|
12 |
"max_output_tokens": 800,
|
13 |
-
#"model": "text-bison@001",
|
14 |
"model": "gemini-pro",
|
15 |
"temperature": 0.1,
|
16 |
"top_k": 40,
|
@@ -30,8 +29,6 @@ vertexai.init(project = project,
|
|
30 |
credentials = credentials
|
31 |
)
|
32 |
|
33 |
-
#from vertexai.language_models import TextGenerationModel
|
34 |
-
#generation_model = TextGenerationModel.from_pretrained(config["model"])
|
35 |
from vertexai.preview.generative_models import GenerativeModel
|
36 |
generation_model = GenerativeModel(config["model"])
|
37 |
|
@@ -44,39 +41,38 @@ def wandb_log(prompt, completion):
|
|
44 |
def invoke(prompt):
|
45 |
if (prompt == ""):
|
46 |
raise gr.Error("Prompt is required.")
|
|
|
47 |
completion = ""
|
|
|
48 |
try:
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
completion = generation_model.generate_content(prompt, generation_config = {
|
58 |
-
"max_output_tokens": config["max_output_tokens"],
|
59 |
-
"temperature": config["temperature"],
|
60 |
-
"top_k": config["top_k"],
|
61 |
-
"top_p": config["top_p"],
|
62 |
-
})
|
63 |
if (completion.text != None):
|
64 |
completion = completion.text
|
65 |
except Exception as e:
|
66 |
completion = e
|
|
|
67 |
raise gr.Error(e)
|
68 |
finally:
|
69 |
wandb_log(prompt, completion)
|
|
|
70 |
return completion
|
71 |
-
#return "🛑 Execution is commented out. To view the source code see https://huggingface.co/spaces/bstraehle/google-vertex-ai-llm/tree/main."
|
72 |
|
73 |
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
|
74 |
with gemini-pro foundation model. RAG evaluation via <a href='https://wandb.ai/bstraehle'>Weights & Biases</a>."""
|
75 |
|
76 |
gr.close_all()
|
77 |
-
|
|
|
78 |
inputs = [gr.Textbox(label = "Prompt", lines = 1)],
|
79 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
80 |
title = "Generative AI - LLM",
|
81 |
description = description)
|
|
|
82 |
demo.launch()
|
|
|
10 |
|
11 |
config = {
|
12 |
"max_output_tokens": 800,
|
|
|
13 |
"model": "gemini-pro",
|
14 |
"temperature": 0.1,
|
15 |
"top_k": 40,
|
|
|
29 |
credentials = credentials
|
30 |
)
|
31 |
|
|
|
|
|
32 |
from vertexai.preview.generative_models import GenerativeModel
|
33 |
generation_model = GenerativeModel(config["model"])
|
34 |
|
|
|
41 |
def invoke(prompt):
|
42 |
if (prompt == ""):
|
43 |
raise gr.Error("Prompt is required.")
|
44 |
+
|
45 |
completion = ""
|
46 |
+
|
47 |
try:
|
48 |
+
completion = generation_model.generate_content(prompt,
|
49 |
+
generation_config = {
|
50 |
+
"max_output_tokens": config["max_output_tokens"],
|
51 |
+
"temperature": config["temperature"],
|
52 |
+
"top_k": config["top_k"],
|
53 |
+
"top_p": config["top_p"],
|
54 |
+
})
|
55 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if (completion.text != None):
|
57 |
completion = completion.text
|
58 |
except Exception as e:
|
59 |
completion = e
|
60 |
+
|
61 |
raise gr.Error(e)
|
62 |
finally:
|
63 |
wandb_log(prompt, completion)
|
64 |
+
|
65 |
return completion
|
|
|
66 |
|
67 |
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
|
68 |
with gemini-pro foundation model. RAG evaluation via <a href='https://wandb.ai/bstraehle'>Weights & Biases</a>."""
|
69 |
|
70 |
gr.close_all()
|
71 |
+
|
72 |
+
demo = gr.Interface(fn = invoke,
|
73 |
inputs = [gr.Textbox(label = "Prompt", lines = 1)],
|
74 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
75 |
title = "Generative AI - LLM",
|
76 |
description = description)
|
77 |
+
|
78 |
demo.launch()
|