Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,6 @@ def respond(message, history):
|
|
21 |
|
22 |
# encode + generate
|
23 |
inputs = tokenizer(prompt, return_tensors="pt")
|
24 |
-
logging.info(f"Inputs: {inputs}")
|
25 |
outputs = model.generate(
|
26 |
**inputs,
|
27 |
max_new_tokens=200,
|
@@ -36,16 +35,13 @@ def respond(message, history):
|
|
36 |
|
37 |
answer_vi = translator_en2vi.translate(answer)
|
38 |
|
39 |
-
#
|
40 |
-
if
|
41 |
-
|
42 |
-
history.append((message, answer_vi))
|
43 |
-
return "", history
|
44 |
|
45 |
-
#
|
46 |
history.append((message, answer_vi))
|
47 |
|
48 |
-
# Ensure the returned history format is a valid list of tuples
|
49 |
return "", history
|
50 |
|
51 |
# 3) Gradio ChatInterface
|
|
|
21 |
|
22 |
# encode + generate
|
23 |
inputs = tokenizer(prompt, return_tensors="pt")
|
|
|
24 |
outputs = model.generate(
|
25 |
**inputs,
|
26 |
max_new_tokens=200,
|
|
|
35 |
|
36 |
answer_vi = translator_en2vi.translate(answer)
|
37 |
|
38 |
+
# Ensure that the response is a valid string and not empty
|
39 |
+
if not answer_vi.strip(): # if the response is empty
|
40 |
+
answer_vi = "Sorry, I couldn't understand the question."
|
|
|
|
|
41 |
|
42 |
+
# Add to history and return it
|
43 |
history.append((message, answer_vi))
|
44 |
|
|
|
45 |
return "", history
|
46 |
|
47 |
# 3) Gradio ChatInterface
|