Spaces:
Build error
Build error
| import gradio as gr | |
| from deliverable2 import URLValidator | |
| # Instantiate the validator | |
| validator = URLValidator() | |
| # β Ensure queries and URLs are properly formatted | |
| queries = [ | |
| "How does climate change impact global weather?", | |
| "What are the latest advancements in AI?", | |
| "How does diet influence mental health?", | |
| "What are the effects of space travel on astronauts?", | |
| "Is cryptocurrency a safe investment?", | |
| "What are the advantages of renewable energy?", | |
| "How does deep learning work?", | |
| "What are the health risks of 5G technology?", | |
| "Is intermittent fasting effective for weight loss?", | |
| "How do electric vehicles compare to gas cars?", | |
| "What are the best ways to learn a new language?", | |
| "What are the side effects of caffeine?", | |
| "How does exercise affect mental health?", | |
| "Is a vegan diet good for your health?", | |
| "What is the best way to improve sleep quality?" | |
| ] | |
| urls = [ | |
| "https://www.nationalgeographic.com/environment/article/climate-change", | |
| "https://www.technologyreview.com/2023/05/01/latest-ai-advancements/", | |
| "https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower", | |
| "https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel", | |
| "https://www.investopedia.com/terms/c/cryptocurrency.asp", | |
| "https://www.energy.gov/eere/renewable-energy", | |
| "https://www.ibm.com/cloud/deep-learning", | |
| "https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health", | |
| "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/", | |
| "https://www.tesla.com/blog/benefits-of-electric-vehicles", | |
| "https://www.duolingo.com/blog/best-way-to-learn-a-new-language", | |
| "https://www.mayoclinic.org/drugs-supplements/caffeine-oral-route/side-effects", | |
| "https://www.cdc.gov/physicalactivity/basics/pa-health/index.htm", | |
| "https://www.healthline.com/nutrition/vegan-diet-benefits", | |
| "https://www.sleepfoundation.org/how-sleep-works/how-to-get-better-sleep" | |
| ] | |
| # Function to validate URL | |
| def validate_url(user_query, url_to_check): | |
| result = validator.rate_url_validity(user_query, url_to_check) | |
| if "Validation Error" in result: | |
| return {"Error": result["Validation Error"]} | |
| return { | |
| "Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100", | |
| "Bias Score": f"{result['raw_score']['Bias Score']} / 100", | |
| "Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100" | |
| } | |
| # Gradio UI | |
| with gr.Blocks() as app: | |
| gr.Markdown("# π URL Credibility Validator") | |
| gr.Markdown("### Validate the credibility of any webpage using AI") | |
| user_query = gr.Dropdown(queries, label="Select a search query:") | |
| url_to_check = gr.Dropdown(urls, label="Select a URL to validate:") | |
| result_output = gr.JSON(label="Validation Results") | |
| submit_button = gr.Button("Validate URL") | |
| submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output) | |
| # Launch the app | |
| app.launch(server_name="0.0.0.0", server_port=7860) | |