Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,93 +1,114 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from deliverable2 import URLValidator
|
| 3 |
|
| 4 |
-
#
|
| 5 |
validator = URLValidator()
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
"What are the symptoms of the flu?",
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
"What are the
|
| 13 |
-
"
|
| 14 |
-
"What are the
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"How
|
| 19 |
-
"What are the effects of
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
"https://www.bbc.com/news/world-us-canada-64879434",
|
| 28 |
-
"https://www.forbes.com/sites/forbestechcouncil/2023/
|
| 29 |
-
"https://www.
|
| 30 |
-
"https://www.
|
| 31 |
-
"https://www.
|
| 32 |
-
"https://www.
|
| 33 |
-
"https://www.
|
| 34 |
-
"https://www.
|
| 35 |
-
"https://www.
|
| 36 |
-
"https://www.
|
| 37 |
-
"https://www.
|
| 38 |
-
"https://www.
|
| 39 |
-
"https://www.
|
| 40 |
-
"https://
|
| 41 |
-
"https://www.
|
| 42 |
]
|
| 43 |
|
| 44 |
-
#
|
| 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"
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 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 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|