ArrcttacsrjksX commited on
Commit
df27c04
·
verified ·
1 Parent(s): 71e45d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -105,11 +105,14 @@ def text_to_image(input_text, font_size, width, height, bg_color, text_color, mo
105
  buf.seek(0)
106
  return buf
107
 
108
- # Function to handle file upload
109
  def handle_file_upload(file, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
110
  """Extract text from file and convert to an image."""
111
  if file is not None:
112
- text = file.read().decode("utf-8") # Read and decode text file
 
 
 
113
  return text_to_image(text, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format)
114
  return "No file uploaded!"
115
 
@@ -123,7 +126,7 @@ with gr.Blocks() as demo:
123
 
124
  with gr.Row():
125
  input_text = gr.Textbox(label="Enter Text", placeholder="Type or paste text here...")
126
- file_input = gr.File(label="Upload a Text File", type="file")
127
 
128
  with gr.Row():
129
  font_size = gr.Slider(10, 100, value=30, label="Font Size")
 
105
  buf.seek(0)
106
  return buf
107
 
108
+ # Function to handle file upload using file path
109
  def handle_file_upload(file, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
110
  """Extract text from file and convert to an image."""
111
  if file is not None:
112
+ # 'file' is a list of file paths; use the first file path.
113
+ file_path = file[0]
114
+ with open(file_path, "r", encoding="utf-8") as f:
115
+ text = f.read()
116
  return text_to_image(text, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format)
117
  return "No file uploaded!"
118
 
 
126
 
127
  with gr.Row():
128
  input_text = gr.Textbox(label="Enter Text", placeholder="Type or paste text here...")
129
+ file_input = gr.File(label="Upload a Text File", type="filepath")
130
 
131
  with gr.Row():
132
  font_size = gr.Slider(10, 100, value=30, label="Font Size")