OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Gradio error: TypeError: gradio.data_classes.FileData() argument after ** must be a mapping, not list

  • Thread starter Thread starter Fraimy
  • Start date Start date
F

Fraimy

Guest
I was trying to build my first interface in Gradio, when I got this error: "Gradio error: TypeError: gradio.data_classes.FileData() argument after ** must be a mapping, not list" (Full error is below the code block).

Code:
import gradio as gr
from time import sleep
import pandas as pd
import random

css = """
.custom-file-input {
    height: 50px;
}
"""

with gr.Blocks(css=css) as ui:
    gr.Markdown(value='#### File for analysis:')
    
    with gr.Row():
        file_input = gr.File(label="Excel or CSV file", elem_classes="custom-file-input", file_count=1)
        analyze_button = gr.Button("Analyze", scale=0)
    
    gr.Markdown(value='### Progress:')
    progress_output = gr.Markdown()
    
    status_text = gr.Textbox(interactive=False, show_label=False, visible=True)
    
    result_file = gr.File(label="Result", interactive=False)
    
    @analyze_button.click(inputs=file_input)
    def process_file(file):
    
        # Simulate file processing and progress updates
        progress = gr.Progress()
        progress(0, desc='0%')
        
        df = pd.read_excel(file.name)
        n_lines = df.shape[0]
        
        for i in range(n_lines):
            # sleep(0.01)  # Simulate some processing time
            df.iloc[i]['Target'] = random.choice(['MOROCCO', 'PRODUCT SKI', 'FINANCE', 'DOMESTIC'])
            progress((i + 1) / n_lines, desc=f'{int((i + 1) / n_lines * 100)}%')

        progress(1, desc='100%')
        
        output_file = "processed_file.xlsx"
        
        df.to_excel(output_file, index=False)
        

ui.launch()

I don't know what to try hoenestly, because it's a new library for me. I tried building a simple gradio interface that reads an excel file and prints out what's inside and it works flawlessly. So, I am guessing it has something to do with handling of output_file probably. Maybe not.

To reproduce: Put any excel file with a few lines of text in the gradio interface and press "Analyze" button to the right of it.
<p>I was trying to build my first interface in Gradio, when I got this error: "Gradio error: TypeError: gradio.data_classes.FileData() argument after ** must be a mapping, not list" (Full error is below the code block).</p>
<pre class="lang-py prettyprint-override"><code>import gradio as gr
from time import sleep
import pandas as pd
import random

css = """
.custom-file-input {
height: 50px;
}
"""

with gr.Blocks(css=css) as ui:
gr.Markdown(value='#### File for analysis:')

with gr.Row():
file_input = gr.File(label="Excel or CSV file", elem_classes="custom-file-input", file_count=1)
analyze_button = gr.Button("Analyze", scale=0)

gr.Markdown(value='### Progress:')
progress_output = gr.Markdown()

status_text = gr.Textbox(interactive=False, show_label=False, visible=True)

result_file = gr.File(label="Result", interactive=False)

@analyze_button.click(inputs=file_input)
def process_file(file):

# Simulate file processing and progress updates
progress = gr.Progress()
progress(0, desc='0%')

df = pd.read_excel(file.name)
n_lines = df.shape[0]

for i in range(n_lines):
# sleep(0.01) # Simulate some processing time
df.iloc['Target'] = random.choice(['MOROCCO', 'PRODUCT SKI', 'FINANCE', 'DOMESTIC'])
progress((i + 1) / n_lines, desc=f'{int((i + 1) / n_lines * 100)}%')

progress(1, desc='100%')

output_file = "processed_file.xlsx"

df.to_excel(output_file, index=False)


ui.launch()
</code></pre>
<p>I don't know what to try hoenestly, because it's a new library for me. I tried building a simple gradio interface that reads an excel file and prints out what's inside and it works flawlessly. So, I am guessing it has something to do with handling of <code>output_file</code> probably. Maybe not.</p>
<p>To reproduce: Put any excel file with a few lines of text in the gradio interface and press "Analyze" button to the right of it.</p>
 

Latest posts

Top