Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pymongo
|
| 3 |
+
def get_mongo_client(mongo_uri):
|
| 4 |
+
client = pymongo.MongoClient (mongo_uri)
|
| 5 |
+
print("Connection to MongoDB successful")
|
| 6 |
+
return client
|
| 7 |
+
mongo_uri ='mongodb+srv://divirao05:GOBXrbl9My4pb6eW@cluster0.oz4tn1s.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'
|
| 8 |
+
mongo_client = get_mongo_client(mongo_uri)
|
| 9 |
+
# Ingest data into MongoDB
|
| 10 |
+
db = mongo_client['crawling_data_new']
|
| 11 |
+
collection = db ['crawler_check']
|
| 12 |
+
def greet(category):
|
| 13 |
+
database=collection.find({})
|
| 14 |
+
data=[]
|
| 15 |
+
for d1 in database:
|
| 16 |
+
data.append(d1)
|
| 17 |
+
if category=='ALL':
|
| 18 |
+
return data
|
| 19 |
+
elif category=='WORKING':
|
| 20 |
+
working=[]
|
| 21 |
+
for i in data:
|
| 22 |
+
if i['status']=='WORKING':
|
| 23 |
+
working.append(i)
|
| 24 |
+
return working
|
| 25 |
+
else:
|
| 26 |
+
not_working=[]
|
| 27 |
+
for i in data:
|
| 28 |
+
if i['status']=='ERROR':
|
| 29 |
+
not_working.append(i)
|
| 30 |
+
return not_working
|
| 31 |
+
|
| 32 |
+
demo = gr.Interface(
|
| 33 |
+
greet,
|
| 34 |
+
[
|
| 35 |
+
gr.Dropdown(
|
| 36 |
+
["ALL", "WORKING", "NOT WORKING"], label="STATUS"
|
| 37 |
+
)
|
| 38 |
+
],
|
| 39 |
+
"text",
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
demo.launch()
|