Spaces:
Sleeping
Sleeping
File size: 943 Bytes
d89084e 74f0713 d89084e 74f0713 d89084e 74f0713 d89084e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
from gradio.components import Textbox
from gradio.components.base import Component
from gradio import component
@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"
|