marwanto606 commited on
Commit
eea58a2
·
verified ·
1 Parent(s): 29f9918

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+ def extract_text_from_url(url):
5
+ try:
6
+ # Request data from the URL
7
+ response = requests.get(url)
8
+ response.raise_for_status() # Raise an error for bad responses
9
+ data = response.json()
10
+
11
+ # Extract 'text' from each row
12
+ rows = data.get("rows", [])
13
+ texts = [row["row"]["text"] for row in rows if "text" in row["row"]]
14
+
15
+ # Return as a single string with newlines
16
+ return "\n".join(texts)
17
+ except Exception as e:
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."
27
+ )
28
+
29
+ if __name__ == "__main__":
30
+ interface.launch()