SaiKumar1627 commited on
Commit
cff0d68
Β·
verified Β·
1 Parent(s): c25b170

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -74
app.py CHANGED
@@ -1,93 +1,114 @@
1
  import gradio as gr
2
  from deliverable2 import URLValidator
3
 
4
- # βœ… Instantiate the URLValidator class
5
  validator = URLValidator()
6
 
7
- # βœ… Define the queries and URLs (15 entries each)
8
- sample_queries = [
9
  "What are the symptoms of the flu?",
10
- "How does artificial intelligence impact the job market?",
11
- "What are the risks of genetically modified organisms (GMOs)?",
12
- "What are the environmental effects of plastic pollution?",
13
- "How does 5G technology affect human health?",
14
- "What are the latest treatments for Alzheimer's disease?",
15
- "Is red meat consumption linked to heart disease?",
16
- "How does cryptocurrency mining impact the environment?",
17
- "What are the benefits of electric cars?",
18
- "How does sleep deprivation affect cognitive function?",
19
- "What are the effects of social media on teenage mental health?",
20
- "What are the ethical concerns of facial recognition technology?",
21
- "How does air pollution contribute to lung diseases?",
22
- "What are the potential dangers of artificial general intelligence?",
23
- "How does meditation impact brain function?"
 
 
 
 
 
 
 
 
 
 
24
  ]
25
 
26
- sample_urls = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  "https://www.bbc.com/news/world-us-canada-64879434",
28
- "https://www.forbes.com/sites/forbestechcouncil/2023/10/15/impact-of-ai-on-the-job-market/",
29
- "https://www.fda.gov/food/food-labeling-nutrition/consumers-guide-gmo-foods",
30
- "https://www.nationalgeographic.com/environment/article/plastic-pollution",
31
- "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7453195/",
32
- "https://www.alz.org/alzheimers-dementia/treatments",
33
- "https://www.heart.org/en/news/2021/02/10/how-red-meat-affects-heart-health",
34
- "https://www.scientificamerican.com/article/how-bitcoin-mining-impacts-the-environment/",
35
- "https://www.tesla.com/blog/environmental-benefits-electric-cars",
36
- "https://www.sleepfoundation.org/sleep-deprivation",
37
- "https://www.psychologytoday.com/us/basics/teenagers-and-social-media",
38
- "https://www.brookings.edu/research/facial-recognition-technology-ethical-concerns/",
39
- "https://www.who.int/news-room/fact-sheets/detail/ambient-(outdoor)-air-quality-and-health",
40
- "https://futureoflife.org/background/benefits-risks-of-artificial-intelligence/",
41
- "https://www.mindful.org/meditation/mindfulness-getting-started/"
42
  ]
43
 
44
- # βœ… Function to validate a selected query and URL
45
  def validate_url(user_query, url_to_check):
46
- """Runs the credibility validation process and returns results."""
47
  result = validator.rate_url_validity(user_query, url_to_check)
48
 
49
- # Handle cases where validation fails
50
  if "Validation Error" in result:
51
- return "Error", "Error", "Error", result["Validation Error"]
52
 
53
- # Extract relevant fields from the result dictionary
54
- func_rating = round(result["raw_score"]["Final Validity Score"] / 20) # Convert 100-scale to 1-5
55
- custom_rating = min(func_rating + 1, 5) # Ensure max rating is 5
56
- stars = result["stars"]["icon"]
57
- explanation = result["explanation"]
58
 
59
- return func_rating, custom_rating, stars, explanation
60
-
61
- # βœ… Define the Gradio UI interface
62
  with gr.Blocks() as app:
63
  gr.Markdown("# 🌍 URL Credibility Validator")
64
- gr.Markdown("Validate the credibility of any webpage using AI.")
65
-
66
- # Dropdown for selecting a query
67
- user_query = gr.Dropdown(
68
- label="Select a search query:",
69
- choices=sample_queries
70
- )
71
-
72
- # Dropdown for selecting a URL
73
- url_to_check = gr.Dropdown(
74
- label="Select a URL to validate:",
75
- choices=sample_urls
76
- )
77
-
78
- # Output fields
79
- func_rating_output = gr.Textbox(label="πŸ”’ Function Rating (1-5)", interactive=False)
80
- custom_rating_output = gr.Textbox(label="⭐ Custom Rating (1-5)", interactive=False)
81
- stars_output = gr.Textbox(label="🌟 Star Rating", interactive=False)
82
- explanation_output = gr.Textbox(label="πŸ“„ Explanation", interactive=False)
83
-
84
- # Validate Button
85
- validate_button = gr.Button("βœ… Validate URL")
86
- validate_button.click(
87
- validate_url,
88
- inputs=[user_query, url_to_check],
89
- outputs=[func_rating_output, custom_rating_output, stars_output, explanation_output]
90
- )
91
-
92
- # βœ… Launch Gradio App
93
- app.launch()
 
1
  import gradio as gr
2
  from deliverable2 import URLValidator
3
 
4
+ # Initialize Validator
5
  validator = URLValidator()
6
 
7
+ # Define queries and URLs
8
+ queries = [
9
  "What are the symptoms of the flu?",
10
+ "What are the latest advancements in AI?",
11
+ "How does diet influence mental health?",
12
+ "What are the effects of space travel on astronauts?",
13
+ "Is cryptocurrency a safe investment?",
14
+ "What are the advantages of renewable energy?",
15
+ "How does deep learning work?",
16
+ "What are the health risks of 5G technology?",
17
+ "Is intermittent fasting effective for weight loss?",
18
+ "How do electric vehicles compare to gas cars?",
19
+ "What are the side effects of caffeine?",
20
+ "How does climate change impact global weather?",
21
+ "What is the be "https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
22
+ "https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
23
+ "https://www.investopedia.com/terms/c/cryptocurrency.asp",
24
+ "https://www.energy.gov/eere/renewable-energy",
25
+ "https://www.ibm.com/cloud/deep-learning",
26
+ "https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health",
27
+ "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/",
28
+ "https://www.tesla.com/blog/benefits-of-electric-vehicles",
29
+ "https://www.mayoclinic.org/drugs-supplements/caffeine-oral-route/side-effects",
30
+ "https://www.nationalgeographic.com/environment/article/climate-change",
31
+ "https://www.duolingo.com/blog/best-way-to-learn-a-new-language",
32
+ "https://www.tesla.com/blog/are-electric-cars-better-than-gasoline-cars",
33
+ "https://www.healthline.com/nutrition/vegan-diet-benefits"
34
  ]
35
 
36
+ # Function to validate URL
37
+ def validate_url(user_query, url_to_check):
38
+ result = validator.rate_url_validity(user_query, url_to_check)
39
+
40
+ if "Validation Error" in result:
41
+ return {"Error": result["Validation Error"]}
42
+
43
+ return {
44
+ "Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
45
+ "Bias Score": f"{result['raw_score']['Bias Score']} / 100",
46
+ "Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
47
+ }
48
+
49
+ # Gradio UI
50
+ with gr.Blocks() as app:
51
+ gr.Markdown("# 🌍 URL Credibility Validator")
52
+ gr.Markdown("### Validate the credibility of any webpage using AI")
53
+
54
+ user_query = gr.Dropdown(queries, label="Select a search query:")
55
+ url_to_check = gr.Dropdown(urls, label="Select a URL to validate:")
56
+
57
+ result_output = gr.JSON(label="Validation Results")
58
+
59
+ submit_button = gr.Button("Validate URL")
60
+ submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output)
61
+
62
+ # Launch the app
63
+ app.launch(server_name="0.0.0.0", server_port=7860)
64
+ st way to learn a new language?",
65
+ "Are electric cars better than gasoline cars?",
66
+ "What are the benefits of a vegan diet?"
67
+ ]
68
+
69
+ urls = [
70
  "https://www.bbc.com/news/world-us-canada-64879434",
71
+ "https://www.forbes.com/sites/forbestechcouncil/2023/02/20/ai-latest-developments
72
+ "https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
73
+ "https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
74
+ "https://www.investopedia.com/terms/c/cryptocurrency.asp",
75
+ "https://www.energy.gov/eere/renewable-energy",
76
+ "https://www.ibm.com/cloud/deep-learning",
77
+ "https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health",
78
+ "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/",
79
+ "https://www.tesla.com/blog/benefits-of-electric-vehicles",
80
+ "https://www.mayoclinic.org/drugs-supplements/caffeine-oral-route/side-effects",
81
+ "https://www.nationalgeographic.com/environment/article/climate-change",
82
+ "https://www.duolingo.com/blog/best-way-to-learn-a-new-language",
83
+ "https://www.tesla.com/blog/are-electric-cars-better-than-gasoline-cars",
84
+ "https://www.healthline.com/nutrition/vegan-diet-benefits"
85
  ]
86
 
87
+ # Function to validate URL
88
  def validate_url(user_query, url_to_check):
 
89
  result = validator.rate_url_validity(user_query, url_to_check)
90
 
 
91
  if "Validation Error" in result:
92
+ return {"Error": result["Validation Error"]}
93
 
94
+ return {
95
+ "Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
96
+ "Bias Score": f"{result['raw_score']['Bias Score']} / 100",
97
+ "Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
98
+ }
99
 
100
+ # Gradio UI
 
 
101
  with gr.Blocks() as app:
102
  gr.Markdown("# 🌍 URL Credibility Validator")
103
+ gr.Markdown("### Validate the credibility of any webpage using AI")
104
+
105
+ user_query = gr.Dropdown(queries, label="Select a search query:")
106
+ url_to_check = gr.Dropdown(urls, label="Select a URL to validate:")
107
+
108
+ result_output = gr.JSON(label="Validation Results")
109
+
110
+ submit_button = gr.Button("Validate URL")
111
+ submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output)
112
+
113
+ # Launch the app
114
+ app.launch(server_name="0.0.0.0", server_port=7860)