marwanto606 commited on
Commit
e68599c
·
verified ·
1 Parent(s): 103ee4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -45
app.py CHANGED
@@ -18,50 +18,13 @@ def extract_text_from_url(url):
18
  return f"An error occurred: {e}"
19
 
20
  # Gradio interface
21
- with gr.Blocks() as app:
22
- gr.Markdown("### Extract Text from Hugging Face Dataset")
23
- gr.Markdown(
24
- "Enter the URL of a Hugging Face dataset to extract and display the 'text' fields. "
25
- "Example URL: https://datasets-server.huggingface.co/rows?dataset=pszemraj%2Fmidjourney-messages-cleaned&config=deduped&split=train&length=100&offset=0"
26
- )
27
-
28
- with gr.Row():
29
- dataset_url = gr.Textbox(
30
- label="Dataset URL",
31
- placeholder="Enter the dataset URL",
32
- lines=1
33
- )
34
-
35
- extracted_texts = gr.Textbox(
36
- label="Extracted Texts",
37
- lines=20,
38
- placeholder="Extracted texts will appear here",
39
- interactive=False,
40
- elem_id="extracted-texts" # Add unique ID for JavaScript targeting
41
- )
42
-
43
- with gr.Row():
44
- extract_button = gr.Button("Extract Texts")
45
- # Add custom HTML for copy functionality
46
- copy_button_html = gr.HTML("""
47
- <button id="copy-btn" style="padding: 10px; background-color: #007bff; color: white; border: none; cursor: pointer;">
48
- Copy All
49
- </button>
50
- <script>
51
- document.getElementById("copy-btn").addEventListener("click", function() {
52
- const text = document.getElementById("extracted-texts").value;
53
- navigator.clipboard.writeText(text).then(function() {
54
- alert("Texts copied to clipboard!");
55
- }).catch(function(err) {
56
- alert("Failed to copy text: " + err);
57
- });
58
- });
59
- </script>
60
- """)
61
 
62
- # Define the interaction for extracting text
63
- extract_button.click(extract_text_from_url, inputs=dataset_url, outputs=extracted_texts)
64
-
65
- # Launch the app
66
  if __name__ == "__main__":
67
- app.launch()
 
18
  return f"An error occurred: {e}"
19
 
20
  # Gradio interface
21
+ interface = gr.Interface(
22
+ fn=extract_text_from_url,
23
+ inputs=gr.Textbox(label="Dataset URL", placeholder="Enter the dataset URL"),
24
+ outputs=gr.Textbox(label="Extracted Texts", lines=20, placeholder="Extracted texts will appear here"),
25
+ title="Extract Text from Hugging Face Dataset",
26
+ description="Enter the URL of a Hugging Face dataset to extract and display the 'text' fields. https://datasets-server.huggingface.co/rows?dataset=pszemraj%2Fmidjourney-messages-cleaned&config=deduped&split=train&length=100&offset=0"
27
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
 
 
 
 
29
  if __name__ == "__main__":
30
+ interface.launch()