Ai Lab 02
Ai Lab 02
Karachi Campus
Submitted On:
Date: 26/02/2024
Solution:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
def load_dataset(file_path):
# Load dataset
try:
df = pd.read_csv(file_path)
return df
except FileNotFoundError:
print("File not found. Please make sure the file path is correct.")
def explore_data(df):
# Display basic information about the dataset
print("Dataset Info:")
print(df.info())
def create_visualizations(df):
# Create interactive visualizations
print("\nGenerating Visualizations...")
def main():
# Load dataset
file_path = 'Train.csv' # Assuming 'Train.csv' is in the same directory
if df is not None:
# Explore the data
explore_data(df)
# Create visualizations
create_visualizations(df)
if __name__ == "__main__":
main()
Output:
Solution:
Solution:
Solution:
import requests
from bs4 import BeautifulSoup
import csv
import json
def scrape_video_info(url):
# Send a GET request to the URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content using Beautiful Soup
soup = BeautifulSoup(response.content, 'html.parser')
# Extract video information
video_title = soup.find('h1', class_='title style-scope ytd-video-primary-info-
renderer').text.strip()
video_description = soup.find('div', id='description').text.strip()
video_views = soup.find('span', class_='view-count style-scope yt-view-count-
renderer').text.strip()
video_likes = soup.find('yt-formatted-string', id='text', class_='style-scope ytd-
toggle-button-renderer style-text').text.strip()
video_dislikes = soup.find_all('yt-formatted-string', id='text', class_='style-scope
ytd-toggle-button-renderer')[1].text.strip()
return {
'title': video_title,
'description': video_description,
'views': video_views,
'likes': video_likes,
'dislikes': video_dislikes
}
else:
print("Failed to retrieve page:", response.status_code)
return None
def save_to_csv(video_info_list, file_path):
with open(file_path, 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ['title', 'description', 'views', 'likes', 'dislikes']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for video_info in video_info_list:
writer.writerow(video_info)
def save_to_json(video_info_list, file_path):
with open(file_path, 'w', encoding='utf-8') as jsonfile:
Solution:
import pywhatkit as kit
import datetime
# Function to send a text message
def send_text_message(phone_number, message, time):
kit.sendwhatmsg(phone_number, message, time.hour, time.minute)
# Function to send an image
def send_image(phone_number, image_path, time):
kit.sendwhats_image(phone_number, image_path, time.hour, time.minute)
def main():
# Phone numbers
sender_number = "+923350039418"
receiver_number = "+923332082149"
# Menu for selecting the type of content to send
print("What would you like to send?")
print("1. Text Message")
print("2. Image")
choice = input("Enter your choice (1 or 2): ")
# Content based on user choice
if choice == "1":
# Message to be sent
message = input("Enter the message to send: ")
# Time to send the message
send_time = datetime.datetime.now() + datetime.timedelta(minutes=1) # Sending after 1
minute
# Sending text message
send_text_message(receiver_number, message, send_time)
elif choice == "2":
# Image path (if sending an image)
image_path = input("Enter the path of the image to send: ")
# Time to send the message
send_time = datetime.datetime.now() + datetime.timedelta(minutes=1) # Sending after 1
minute
# Sending image
send_image(receiver_number, image_path, send_time)
else:
print("Invalid choice. Please enter either 1 or 2.")
if __name__ == "__main__":
main()
def main():
# Input text from the user
text = input("Enter the text you want to convert to speech: ")
# Select language
language = input("Enter the language (e.g., en for English): ")
# Select gender
gender = input("Enter the gender of the voice (male/female): ")
if __name__ == "__main__":
main()