Sg-at-srijan-us-kg commited on
Commit
c9b44f8
·
verified ·
1 Parent(s): 13e38e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -18,8 +18,11 @@ def respond(
18
  # Read file content if a file is uploaded
19
  if file is not None:
20
  try:
21
- # Attempt to read the file content directly from the file object
22
- file_content = file.read().decode("utf-8") # Read and decode bytes to string
 
 
 
23
  print("File content:", file_content) # Debug print
24
  message = f"{file_content}\n\n{message}" # Append file content to message
25
  except Exception as e:
@@ -69,3 +72,4 @@ demo = gr.ChatInterface(
69
 
70
  if __name__ == "__main__":
71
  demo.launch()
 
 
18
  # Read file content if a file is uploaded
19
  if file is not None:
20
  try:
21
+ if hasattr(file, 'value'): # Check if file is a NamedString or similar
22
+ file_content = file.value.decode("utf-8") # Decode the string content
23
+ else:
24
+ file_content = file.read().decode("utf-8") # Fallback for other file types
25
+
26
  print("File content:", file_content) # Debug print
27
  message = f"{file_content}\n\n{message}" # Append file content to message
28
  except Exception as e:
 
72
 
73
  if __name__ == "__main__":
74
  demo.launch()
75
+