Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import google.generativeai as genai
|
|
5 |
import gradio as gr
|
6 |
|
7 |
# Get the Google API key from environment variables
|
8 |
-
|
9 |
|
10 |
# Define the title and subtitle for the Gradio interface
|
11 |
TITLE = """<h1 align="center">ποΈ AI Personal Trainer Playground πͺ</h1>"""
|
@@ -34,6 +34,7 @@ def user(text_prompt: str, chatbot: List[Tuple[str, str]]):
|
|
34 |
|
35 |
# Function to handle bot response
|
36 |
def bot(
|
|
|
37 |
model_name: str,
|
38 |
video_prompt,
|
39 |
temperature: float,
|
@@ -44,7 +45,13 @@ def bot(
|
|
44 |
text_prompt_component: str,
|
45 |
chatbot: List[Tuple[str, str]]
|
46 |
):
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Combine the user input with the predefined prompt
|
49 |
user_input = chatbot[-1][0]
|
50 |
combined_prompt = Prompt + "\n" + user_input
|
@@ -96,6 +103,15 @@ def bot(
|
|
96 |
time.sleep(0.01)
|
97 |
yield chatbot
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
video_prompt_component = gr.Video(label="Video", autoplay=True)
|
101 |
|
@@ -173,6 +189,7 @@ top_p_component = gr.Slider(
|
|
173 |
user_inputs = [text_prompt_component, chatbot_component]
|
174 |
|
175 |
bot_inputs = [
|
|
|
176 |
model_selection,
|
177 |
video_prompt_component,
|
178 |
temperature_component,
|
@@ -189,6 +206,7 @@ with gr.Blocks() as demo:
|
|
189 |
gr.HTML(TITLE)
|
190 |
gr.HTML(SUBTITLE)
|
191 |
with gr.Column():
|
|
|
192 |
with gr.Row():
|
193 |
video_prompt_component.render()
|
194 |
chatbot_component.render()
|
|
|
5 |
import gradio as gr
|
6 |
|
7 |
# Get the Google API key from environment variables
|
8 |
+
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
9 |
|
10 |
# Define the title and subtitle for the Gradio interface
|
11 |
TITLE = """<h1 align="center">ποΈ AI Personal Trainer Playground πͺ</h1>"""
|
|
|
34 |
|
35 |
# Function to handle bot response
|
36 |
def bot(
|
37 |
+
google_key: str,
|
38 |
model_name: str,
|
39 |
video_prompt,
|
40 |
temperature: float,
|
|
|
45 |
text_prompt_component: str,
|
46 |
chatbot: List[Tuple[str, str]]
|
47 |
):
|
48 |
+
# Use the provided Google API key or the one from environment variables
|
49 |
+
google_key = google_key if google_key else GOOGLE_API_KEY
|
50 |
+
if not google_key:
|
51 |
+
raise ValueError(
|
52 |
+
"GOOGLE_API_KEY is not set. "
|
53 |
+
"Please follow the instructions in the README to set it up.")
|
54 |
+
|
55 |
# Combine the user input with the predefined prompt
|
56 |
user_input = chatbot[-1][0]
|
57 |
combined_prompt = Prompt + "\n" + user_input
|
|
|
103 |
time.sleep(0.01)
|
104 |
yield chatbot
|
105 |
|
106 |
+
# Define Gradio components
|
107 |
+
google_key_component = gr.Textbox(
|
108 |
+
label="GOOGLE API KEY",
|
109 |
+
value="",
|
110 |
+
type="password",
|
111 |
+
placeholder="...",
|
112 |
+
info="You have to provide your own GOOGLE_API_KEY for this app to function properly",
|
113 |
+
visible=GOOGLE_API_KEY is None
|
114 |
+
)
|
115 |
|
116 |
video_prompt_component = gr.Video(label="Video", autoplay=True)
|
117 |
|
|
|
189 |
user_inputs = [text_prompt_component, chatbot_component]
|
190 |
|
191 |
bot_inputs = [
|
192 |
+
google_key_component,
|
193 |
model_selection,
|
194 |
video_prompt_component,
|
195 |
temperature_component,
|
|
|
206 |
gr.HTML(TITLE)
|
207 |
gr.HTML(SUBTITLE)
|
208 |
with gr.Column():
|
209 |
+
google_key_component.render()
|
210 |
with gr.Row():
|
211 |
video_prompt_component.render()
|
212 |
chatbot_component.render()
|