ThongCoding commited on
Commit
8c4c569
·
verified ·
1 Parent(s): 8bec2a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
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
- # Check if the response includes any files
40
- if isinstance(answer_vi, str) and answer_vi.startswith("file:"):
41
- # Handle the file response separately (you can modify this logic based on your requirements)
42
- history.append((message, answer_vi))
43
- return "", history
44
 
45
- # thêm vào history return
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