Spaces:
Sleeping
Sleeping
import gradio as gr | |
from gradio.components import Textbox | |
from gradio.components.base import Component | |
from gradio import component | |
class TextboxWithUpload(Textbox): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.upload_button = None | |
self.add_upload_button() | |
def add_upload_button(self): | |
self.upload_button = gr.UploadButton("π", file_types=["text"], file_count="single") | |
self.upload_button.upload(self.handle_upload, inputs=[self.upload_button], outputs=[self]) | |
def handle_upload(self, file): | |
if file: | |
return file.name | |
return "" | |
def get_template_context(self): | |
context = super().get_template_context() | |
if self.upload_button: | |
context["upload_button"] = self.upload_button.get_template_context() | |
return context | |
def get_block_name(self): | |
return "textboxwithupload" | |