Sg-at-srijan-us-kg commited on
Commit
4ad4683
·
verified ·
1 Parent(s): 410b7f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -7,14 +7,14 @@ client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
7
  uploaded_file_content = ""
8
 
9
  # A function to handle file upload and store content
10
- def handle_file_upload(file):
11
  global uploaded_file_content
12
- if file is None:
13
  return "No file uploaded."
14
 
15
  try:
16
- # Read the file content directly
17
- content = file.read()
18
 
19
  # Try to decode as UTF-8
20
  try:
@@ -97,7 +97,7 @@ with demo:
97
  file_upload = gr.File(
98
  label="Upload a text file",
99
  file_types=[".txt"],
100
- type="binary" # Important: Set type to binary
101
  )
102
  upload_button = gr.Button("Upload File")
103
  upload_output = gr.Textbox(
 
7
  uploaded_file_content = ""
8
 
9
  # A function to handle file upload and store content
10
+ def handle_file_upload(file_obj):
11
  global uploaded_file_content
12
+ if file_obj is None:
13
  return "No file uploaded."
14
 
15
  try:
16
+ # The file is already passed as bytes in the newest Gradio version
17
+ content = file_obj
18
 
19
  # Try to decode as UTF-8
20
  try:
 
97
  file_upload = gr.File(
98
  label="Upload a text file",
99
  file_types=[".txt"],
100
+ type="bytes" # Changed to bytes type
101
  )
102
  upload_button = gr.Button("Upload File")
103
  upload_output = gr.Textbox(