Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from PIL import Image
|
|
| 9 |
|
| 10 |
print("google-generativeai:", genai.__version__)
|
| 11 |
|
|
|
|
| 12 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 13 |
|
| 14 |
TITLE = """<h1 align="center">Gemini Playground 💬</h1>"""
|
|
@@ -57,7 +58,6 @@ def user(text_prompt: str, chatbot: CHAT_HISTORY):
|
|
| 57 |
return "", chatbot
|
| 58 |
|
| 59 |
def bot(
|
| 60 |
-
google_key: str,
|
| 61 |
files: Optional[List[str]],
|
| 62 |
temperature: float,
|
| 63 |
max_output_tokens: int,
|
|
@@ -66,10 +66,11 @@ def bot(
|
|
| 66 |
top_p: float,
|
| 67 |
chatbot: CHAT_HISTORY
|
| 68 |
):
|
| 69 |
-
if not
|
| 70 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
generation_config = genai.types.GenerationConfig(
|
| 74 |
temperature=temperature,
|
| 75 |
max_output_tokens=max_output_tokens,
|
|
@@ -92,14 +93,6 @@ def bot(
|
|
| 92 |
time.sleep(0.01)
|
| 93 |
yield chatbot
|
| 94 |
|
| 95 |
-
google_key_component = gr.Textbox(
|
| 96 |
-
label="GOOGLE API KEY",
|
| 97 |
-
value="",
|
| 98 |
-
type="password",
|
| 99 |
-
placeholder="...",
|
| 100 |
-
info="Please provide your own GOOGLE_API_KEY for this app",
|
| 101 |
-
visible=GOOGLE_API_KEY is None
|
| 102 |
-
)
|
| 103 |
chatbot_component = gr.Chatbot(
|
| 104 |
label='Gemini',
|
| 105 |
bubble_full_width=False,
|
|
@@ -154,7 +147,6 @@ user_inputs = [
|
|
| 154 |
]
|
| 155 |
|
| 156 |
bot_inputs = [
|
| 157 |
-
google_key_component,
|
| 158 |
upload_button_component,
|
| 159 |
temperature_component,
|
| 160 |
max_output_tokens_component,
|
|
@@ -169,7 +161,6 @@ with gr.Blocks() as demo:
|
|
| 169 |
gr.HTML(SUBTITLE)
|
| 170 |
gr.HTML(DES)
|
| 171 |
with gr.Column():
|
| 172 |
-
google_key_component.render()
|
| 173 |
chatbot_component.render()
|
| 174 |
with gr.Row():
|
| 175 |
text_prompt_component.render()
|
|
|
|
| 9 |
|
| 10 |
print("google-generativeai:", genai.__version__)
|
| 11 |
|
| 12 |
+
# Cargar la clave de API de las variables de entorno
|
| 13 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
| 14 |
|
| 15 |
TITLE = """<h1 align="center">Gemini Playground 💬</h1>"""
|
|
|
|
| 58 |
return "", chatbot
|
| 59 |
|
| 60 |
def bot(
|
|
|
|
| 61 |
files: Optional[List[str]],
|
| 62 |
temperature: float,
|
| 63 |
max_output_tokens: int,
|
|
|
|
| 66 |
top_p: float,
|
| 67 |
chatbot: CHAT_HISTORY
|
| 68 |
):
|
| 69 |
+
if not GOOGLE_API_KEY:
|
| 70 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
| 71 |
|
| 72 |
+
# Configurar la API con la clave
|
| 73 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 74 |
generation_config = genai.types.GenerationConfig(
|
| 75 |
temperature=temperature,
|
| 76 |
max_output_tokens=max_output_tokens,
|
|
|
|
| 93 |
time.sleep(0.01)
|
| 94 |
yield chatbot
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
chatbot_component = gr.Chatbot(
|
| 97 |
label='Gemini',
|
| 98 |
bubble_full_width=False,
|
|
|
|
| 147 |
]
|
| 148 |
|
| 149 |
bot_inputs = [
|
|
|
|
| 150 |
upload_button_component,
|
| 151 |
temperature_component,
|
| 152 |
max_output_tokens_component,
|
|
|
|
| 161 |
gr.HTML(SUBTITLE)
|
| 162 |
gr.HTML(DES)
|
| 163 |
with gr.Column():
|
|
|
|
| 164 |
chatbot_component.render()
|
| 165 |
with gr.Row():
|
| 166 |
text_prompt_component.render()
|