nicolaakmal commited on
Commit
fb370a1
1 Parent(s): 7ed607e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -160,9 +160,14 @@ def generate_response(inputs):
160
  ]
161
  # Generate the response using the pipeline
162
  response = pipe(messages)
163
- # Extract the generated text from the response and clean it up if necessary
164
- generated_text = response[0]["generated_text"] if response else "No response generated"
165
- return generated_text.strip() # Removing any unwanted whitespace
 
 
 
 
 
166
 
167
  # Antarmuka Gradio
168
  iface = gr.Interface(
 
160
  ]
161
  # Generate the response using the pipeline
162
  response = pipe(messages)
163
+ # Extract the generated assistant's response
164
+ try:
165
+ # Navigate the nested structure to find the assistant's response content
166
+ assistant_response = response[0]["generated_text"][1]["content"]
167
+ return assistant_response.strip() # Clean up any extra whitespace
168
+ except (IndexError, KeyError, TypeError) as e:
169
+ # Handle any errors due to unexpected structure in the response
170
+ return "Error processing response. Please try again."
171
 
172
  # Antarmuka Gradio
173
  iface = gr.Interface(