Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import random
|
|
|
5 |
|
6 |
# Get token from environment variable
|
7 |
hf_token = os.environ.get("HF_TOKEN")
|
@@ -128,10 +129,10 @@ def format_history_for_gradio(history_tuples):
|
|
128 |
# 4. Add input validation
|
129 |
def respond(
|
130 |
message: str,
|
131 |
-
chat_history:
|
132 |
-
genre: str
|
133 |
use_full_memory: bool = True
|
134 |
-
) -> Generator[
|
135 |
"""Generate a response based on the current message and conversation history."""
|
136 |
if not message.strip():
|
137 |
return chat_history
|
@@ -258,14 +259,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
258 |
|
259 |
# 1) We'll return a list of 4 dicts, each dict updating 'value' & 'visible'
|
260 |
def update_starter_buttons(selected_genre):
|
|
|
261 |
examples = get_examples_for_genre(selected_genre)
|
262 |
results = []
|
263 |
for i in range(4):
|
264 |
if i < len(examples):
|
265 |
-
|
|
|
266 |
else:
|
267 |
-
results.append(
|
268 |
-
return tuple(results) #
|
269 |
|
270 |
# 2) Initialize them with "fantasy" so they don't stay "Starter X" on page load
|
271 |
# We'll just call the function and store the results in a variable, then apply them in a .load() event
|
|
|
2 |
import os
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import random
|
5 |
+
from typing import Generator, Dict, List, Tuple, Optional
|
6 |
|
7 |
# Get token from environment variable
|
8 |
hf_token = os.environ.get("HF_TOKEN")
|
|
|
129 |
# 4. Add input validation
|
130 |
def respond(
|
131 |
message: str,
|
132 |
+
chat_history: List[Tuple[str, str]],
|
133 |
+
genre: Optional[str] = None,
|
134 |
use_full_memory: bool = True
|
135 |
+
) -> Generator[List[Dict[str, str]], None, None]:
|
136 |
"""Generate a response based on the current message and conversation history."""
|
137 |
if not message.strip():
|
138 |
return chat_history
|
|
|
259 |
|
260 |
# 1) We'll return a list of 4 dicts, each dict updating 'value' & 'visible'
|
261 |
def update_starter_buttons(selected_genre):
|
262 |
+
"""Update starter buttons with examples for the selected genre."""
|
263 |
examples = get_examples_for_genre(selected_genre)
|
264 |
results = []
|
265 |
for i in range(4):
|
266 |
if i < len(examples):
|
267 |
+
# Return just the string value instead of a dict
|
268 |
+
results.append(examples[i])
|
269 |
else:
|
270 |
+
results.append("") # Empty string for hidden buttons
|
271 |
+
return tuple(results) # Return tuple of strings
|
272 |
|
273 |
# 2) Initialize them with "fantasy" so they don't stay "Starter X" on page load
|
274 |
# We'll just call the function and store the results in a variable, then apply them in a .load() event
|