Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,20 +2,15 @@ import os
|
|
2 |
import time
|
3 |
import uuid
|
4 |
from typing import List, Tuple, Optional, Dict, Union
|
5 |
-
from dotenv import load_dotenv
|
6 |
|
7 |
import google.generativeai as genai
|
8 |
import gradio as gr
|
9 |
from PIL import Image
|
10 |
|
11 |
-
# Cargar las variables de entorno desde el archivo .env
|
12 |
-
load_dotenv()
|
13 |
-
|
14 |
-
# Obtener la clave API desde las variables de entorno
|
15 |
-
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
16 |
-
|
17 |
print("google-generativeai:", genai.__version__)
|
18 |
|
|
|
|
|
19 |
TITLE = """<h1 align="center">Gemini Playground 💬</h1>"""
|
20 |
SUBTITLE = """<h2 align="center">Play with Gemini Pro and Gemini Pro Vision</h2>"""
|
21 |
DES = """
|
@@ -62,6 +57,7 @@ def user(text_prompt: str, chatbot: CHAT_HISTORY):
|
|
62 |
return "", chatbot
|
63 |
|
64 |
def bot(
|
|
|
65 |
files: Optional[List[str]],
|
66 |
temperature: float,
|
67 |
max_output_tokens: int,
|
@@ -70,10 +66,10 @@ def bot(
|
|
70 |
top_p: float,
|
71 |
chatbot: CHAT_HISTORY
|
72 |
):
|
73 |
-
if not GOOGLE_API_KEY:
|
74 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
75 |
-
|
76 |
-
genai.configure(api_key=GOOGLE_API_KEY)
|
77 |
generation_config = genai.types.GenerationConfig(
|
78 |
temperature=temperature,
|
79 |
max_output_tokens=max_output_tokens,
|
@@ -212,4 +208,4 @@ with gr.Blocks() as demo:
|
|
212 |
queue=False
|
213 |
)
|
214 |
|
215 |
-
demo.queue(max_size=99).launch(debug=False, show_error=True)
|
|
|
2 |
import time
|
3 |
import uuid
|
4 |
from typing import List, Tuple, Optional, Dict, Union
|
|
|
5 |
|
6 |
import google.generativeai as genai
|
7 |
import gradio as gr
|
8 |
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>"""
|
15 |
SUBTITLE = """<h2 align="center">Play with Gemini Pro and Gemini Pro Vision</h2>"""
|
16 |
DES = """
|
|
|
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 |
top_p: float,
|
67 |
chatbot: CHAT_HISTORY
|
68 |
):
|
69 |
+
if not google_key and not GOOGLE_API_KEY:
|
70 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
71 |
+
|
72 |
+
genai.configure(api_key=google_key if google_key else GOOGLE_API_KEY)
|
73 |
generation_config = genai.types.GenerationConfig(
|
74 |
temperature=temperature,
|
75 |
max_output_tokens=max_output_tokens,
|
|
|
208 |
queue=False
|
209 |
)
|
210 |
|
211 |
+
demo.queue(max_size=99).launch(debug=False, show_error=True)
|