Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,9 +27,6 @@ IMAGE_CACHE_DIRECTORY = "/tmp"
|
|
27 |
IMAGE_WIDTH = 512
|
28 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
29 |
|
30 |
-
def preprocess_stop_sequences(stop_sequences: str) -> Optional[List[str]]:
|
31 |
-
return [sequence.strip() for sequence in stop_sequences.split(",")] if stop_sequences else None
|
32 |
-
|
33 |
def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
|
34 |
if image:
|
35 |
image_height = int(image.height * IMAGE_WIDTH / image.width)
|
@@ -47,7 +44,6 @@ def upload(files: Optional[List[str]], chatbot: CHAT_HISTORY) -> CHAT_HISTORY:
|
|
47 |
image = Image.open(file).convert('RGB')
|
48 |
image_preview = preprocess_image(image)
|
49 |
if image_preview:
|
50 |
-
# Display a preview of the uploaded image
|
51 |
gr.Image(image_preview).render()
|
52 |
image_path = cache_pil_image(image)
|
53 |
chatbot.append(((image_path,), None))
|
@@ -62,7 +58,6 @@ def bot(
|
|
62 |
files: Optional[List[str]],
|
63 |
temperature: float,
|
64 |
max_output_tokens: int,
|
65 |
-
stop_sequences: str,
|
66 |
top_k: int,
|
67 |
top_p: float,
|
68 |
chatbot: CHAT_HISTORY
|
@@ -70,12 +65,10 @@ def bot(
|
|
70 |
if not GOOGLE_API_KEY:
|
71 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
72 |
|
73 |
-
# Configurar la API con la clave
|
74 |
genai.configure(api_key=GOOGLE_API_KEY)
|
75 |
generation_config = genai.types.GenerationConfig(
|
76 |
temperature=temperature,
|
77 |
max_output_tokens=max_output_tokens,
|
78 |
-
stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
|
79 |
top_k=top_k,
|
80 |
top_p=top_p
|
81 |
)
|
@@ -121,12 +114,6 @@ max_output_tokens_component = gr.Slider(
|
|
121 |
step=1,
|
122 |
label="Token limit",
|
123 |
)
|
124 |
-
stop_sequences_component = gr.Textbox(
|
125 |
-
label="Add stop sequence",
|
126 |
-
value="",
|
127 |
-
type="text",
|
128 |
-
placeholder="STOP, END",
|
129 |
-
)
|
130 |
top_k_component = gr.Slider(
|
131 |
minimum=1,
|
132 |
maximum=40,
|
@@ -151,7 +138,6 @@ bot_inputs = [
|
|
151 |
upload_button_component,
|
152 |
temperature_component,
|
153 |
max_output_tokens_component,
|
154 |
-
stop_sequences_component,
|
155 |
top_k_component,
|
156 |
top_p_component,
|
157 |
chatbot_component
|
@@ -169,7 +155,6 @@ with gr.Blocks() as demo:
|
|
169 |
with gr.Accordion("Parameters", open=False):
|
170 |
temperature_component.render()
|
171 |
max_output_tokens_component.render()
|
172 |
-
stop_sequences_component.render()
|
173 |
with gr.Accordion("Advanced", open=False):
|
174 |
top_k_component.render()
|
175 |
top_p_component.render()
|
|
|
27 |
IMAGE_WIDTH = 512
|
28 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
29 |
|
|
|
|
|
|
|
30 |
def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
|
31 |
if image:
|
32 |
image_height = int(image.height * IMAGE_WIDTH / image.width)
|
|
|
44 |
image = Image.open(file).convert('RGB')
|
45 |
image_preview = preprocess_image(image)
|
46 |
if image_preview:
|
|
|
47 |
gr.Image(image_preview).render()
|
48 |
image_path = cache_pil_image(image)
|
49 |
chatbot.append(((image_path,), None))
|
|
|
58 |
files: Optional[List[str]],
|
59 |
temperature: float,
|
60 |
max_output_tokens: int,
|
|
|
61 |
top_k: int,
|
62 |
top_p: float,
|
63 |
chatbot: CHAT_HISTORY
|
|
|
65 |
if not GOOGLE_API_KEY:
|
66 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
67 |
|
|
|
68 |
genai.configure(api_key=GOOGLE_API_KEY)
|
69 |
generation_config = genai.types.GenerationConfig(
|
70 |
temperature=temperature,
|
71 |
max_output_tokens=max_output_tokens,
|
|
|
72 |
top_k=top_k,
|
73 |
top_p=top_p
|
74 |
)
|
|
|
114 |
step=1,
|
115 |
label="Token limit",
|
116 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
top_k_component = gr.Slider(
|
118 |
minimum=1,
|
119 |
maximum=40,
|
|
|
138 |
upload_button_component,
|
139 |
temperature_component,
|
140 |
max_output_tokens_component,
|
|
|
141 |
top_k_component,
|
142 |
top_p_component,
|
143 |
chatbot_component
|
|
|
155 |
with gr.Accordion("Parameters", open=False):
|
156 |
temperature_component.render()
|
157 |
max_output_tokens_component.render()
|
|
|
158 |
with gr.Accordion("Advanced", open=False):
|
159 |
top_k_component.render()
|
160 |
top_p_component.render()
|