Spaces:
Sleeping
Sleeping
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import gradio as grfrom datasets import load_datasetimport tempfile
def combine_dataset_texts(dataset_name, split, text_column): try: # Load the dataset from Hugging Face Hub dataset = load_dataset(dataset_name, split=split) # Verify the text column exists if text_column not in dataset.column_names: raise gr.Error(f"Column '{text_column}' not found in dataset") # Combine all texts combined_text = "\n\n".join([example[text_column] for example in dataset]) # Create a temporary file with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as f: f.write(combined_text) return f.name except Exception as e: raise gr.Error(f"Error processing dataset: {str(e)}")
# Create Gradio interfacewith gr.Blocks() as demo: gr.Markdown("## Hugging Face Dataset Text Combiner") gr.Markdown("Combine all text files from a Hugging Face dataset into a single file") with gr.Row(): dataset_input = gr.Textbox(label="Dataset Name", placeholder="username/dataset-name") split_input = gr.Textbox(label="Split", value="train") column_input = gr.Textbox(label="Text Column", value="text") submit_btn = gr.Button("Combine Texts") with gr.Row(): output_file = gr.File(label="Combined Text File") error_out = gr.Textbox(label="Error Output", visible=False)
submit_btn.click( fn=combine_dataset_texts, inputs=[dataset_input, split_input, column_input], outputs=output_file, api_name="combine_texts" )
if __name__ == "__main__": demo.launch()app.pyAdded+50