Update README.md
Browse files
README.md
CHANGED
|
@@ -1,112 +1,113 @@
|
|
| 1 |
-
---
|
| 2 |
-
tags: [gradio-custom-component,
|
| 3 |
-
title: gradio_spreadsheetcomponent
|
| 4 |
-
short_description: This component answers questions about spreadsheets.
|
| 5 |
-
colorFrom: blue
|
| 6 |
-
colorTo: yellow
|
| 7 |
-
sdk: gradio
|
| 8 |
-
pinned: false
|
| 9 |
-
app_file: space.py
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
from
|
| 29 |
-
import
|
| 30 |
-
import
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
submit_button
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
<
|
| 69 |
-
<
|
| 70 |
-
<
|
| 71 |
-
<th align="left"
|
| 72 |
-
<th align="left">
|
| 73 |
-
<th align="left">
|
| 74 |
-
</
|
| 75 |
-
</
|
| 76 |
-
|
| 77 |
-
<
|
| 78 |
-
<
|
| 79 |
-
<td align="left"
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
<td align="left">
|
| 88 |
-
</
|
| 89 |
-
</
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
- When used as an
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags: [gradio-custom-component, custom-component-track, gradio-spreadsheet-custom-component]
|
| 3 |
+
title: gradio_spreadsheetcomponent
|
| 4 |
+
short_description: This component answers questions about spreadsheets.
|
| 5 |
+
colorFrom: blue
|
| 6 |
+
colorTo: yellow
|
| 7 |
+
sdk: gradio
|
| 8 |
+
pinned: false
|
| 9 |
+
app_file: space.py
|
| 10 |
+
app_link: https://huggingface.co/spaces/Mustafiz996/gradio_spreadsheetcomponent
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# `gradio_spreadsheetcomponent`
|
| 14 |
+
<a href="https://pypi.org/project/gradio_spreadsheetcomponent/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_spreadsheetcomponent"></a>
|
| 15 |
+
|
| 16 |
+
This component is used to answer questions about spreadsheets.
|
| 17 |
+
|
| 18 |
+
## Installation
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
pip install gradio_spreadsheetcomponent
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
import gradio as gr
|
| 28 |
+
from gradio_spreadsheetcomponent import SpreadsheetComponent
|
| 29 |
+
from dotenv import load_dotenv
|
| 30 |
+
import os
|
| 31 |
+
import pandas as pd
|
| 32 |
+
|
| 33 |
+
def answer_question(file, question):
|
| 34 |
+
if not file or not question:
|
| 35 |
+
return "Please upload a file and enter a question."
|
| 36 |
+
|
| 37 |
+
# Load the spreadsheet data
|
| 38 |
+
df = pd.read_excel(file.name)
|
| 39 |
+
|
| 40 |
+
# Create a SpreadsheetComponent instance
|
| 41 |
+
spreadsheet = SpreadsheetComponent(value=df)
|
| 42 |
+
|
| 43 |
+
# Use the component to answer the question
|
| 44 |
+
return spreadsheet.answer_question(question)
|
| 45 |
+
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
+
gr.Markdown("# Spreadsheet Question Answering")
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
file_input = gr.File(label="Upload Spreadsheet", file_types=[".xlsx"])
|
| 51 |
+
question_input = gr.Textbox(label="Ask a Question")
|
| 52 |
+
|
| 53 |
+
answer_output = gr.Textbox(label="Answer", interactive=False, lines=4)
|
| 54 |
+
|
| 55 |
+
submit_button = gr.Button("Submit")
|
| 56 |
+
submit_button.click(answer_question, inputs=[file_input, question_input], outputs=answer_output)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## `SpreadsheetComponent`
|
| 65 |
+
|
| 66 |
+
### Initialization
|
| 67 |
+
|
| 68 |
+
<table>
|
| 69 |
+
<thead>
|
| 70 |
+
<tr>
|
| 71 |
+
<th align="left">name</th>
|
| 72 |
+
<th align="left" style="width: 25%;">type</th>
|
| 73 |
+
<th align="left">default</th>
|
| 74 |
+
<th align="left">description</th>
|
| 75 |
+
</tr>
|
| 76 |
+
</thead>
|
| 77 |
+
<tbody>
|
| 78 |
+
<tr>
|
| 79 |
+
<td align="left"><code>value</code></td>
|
| 80 |
+
<td align="left" style="width: 25%;">
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
pandas.core.frame.DataFrame | list | dict | None
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
</td>
|
| 87 |
+
<td align="left"><code>None</code></td>
|
| 88 |
+
<td align="left">Default value to show in spreadsheet. Can be a pandas DataFrame, list of lists, or dictionary</td>
|
| 89 |
+
</tr>
|
| 90 |
+
</tbody></table>
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
### User function
|
| 96 |
+
|
| 97 |
+
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
|
| 98 |
+
|
| 99 |
+
- When used as an Input, the component only impacts the input signature of the user function.
|
| 100 |
+
- When used as an output, the component only impacts the return signature of the user function.
|
| 101 |
+
|
| 102 |
+
The code snippet below is accurate in cases where the component is used as both an input and an output.
|
| 103 |
+
|
| 104 |
+
- **As output:** Is passed, the preprocessed input data sent to the user's function in the backend.
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
def predict(
|
| 109 |
+
value: typing.Any
|
| 110 |
+
) -> Unknown:
|
| 111 |
+
return value
|
| 112 |
+
```
|
| 113 |
+
|