Python Notes will be uploaded tomorrow, make sure to Join this Channel.
👍30
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
# Sample training data (manually added)
texts = [
"NASA finds water on Mars",
"Apple launches new iPhone with AI",
"Aliens have landed in Delhi",
"Government bans all smartphones",
"COVID-19 vaccine approved worldwide",
"World ends tomorrow",
"Elon Musk buys the Moon",
"UN announces global peace treaty",
]
labels = ["REAL", "REAL", "FAKE", "FAKE", "REAL", "FAKE", "FAKE", "REAL"]
# Step 1: Preprocess
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(texts)
# Step 2: Train model
model = LogisticRegression()
model.fit(X, labels)
# Step 3: Take input and predict
headline = input("📰 Enter a news headline: ")
headline_vec = vectorizer.transform([headline])
prediction = model.predict(headline_vec)
print(" This news is:", "FAKE " if prediction[0] == "FAKE" else "REAL ")
from sklearn.linear_model import LogisticRegression
# Sample training data (manually added)
texts = [
"NASA finds water on Mars",
"Apple launches new iPhone with AI",
"Aliens have landed in Delhi",
"Government bans all smartphones",
"COVID-19 vaccine approved worldwide",
"World ends tomorrow",
"Elon Musk buys the Moon",
"UN announces global peace treaty",
]
labels = ["REAL", "REAL", "FAKE", "FAKE", "REAL", "FAKE", "FAKE", "REAL"]
# Step 1: Preprocess
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(texts)
# Step 2: Train model
model = LogisticRegression()
model.fit(X, labels)
# Step 3: Take input and predict
headline = input("📰 Enter a news headline: ")
headline_vec = vectorizer.transform([headline])
prediction = model.predict(headline_vec)
print(" This news is:", "FAKE " if prediction[0] == "FAKE" else "REAL ")
❤10🔥6👍2
from instabot import Bot
bot = Bot()
#Login
bot.login(username="your_username", password="your_password")
#Don't use your main account because it might get affected!
#Create a demo account for test purpose!
#Follow a user
bot.follow("elonmusk")
#comment
bot.comment("coding","Great content!")
#send DM to someone
bot.send_message("Hey! Big fan",["python.science","only_programming"])
bot = Bot()
#Login
bot.login(username="your_username", password="your_password")
#Don't use your main account because it might get affected!
#Create a demo account for test purpose!
#Follow a user
bot.follow("elonmusk")
#comment
bot.comment("coding","Great content!")
#send DM to someone
bot.send_message("Hey! Big fan",["python.science","only_programming"])
❤7🔥3
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY")
messages = [
{"role": "system", "content": "You are an intelligent assistant."}
]
while True:
message = input("User : ")
if message:
messages.append({"role": "user", "content": message})
chat = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages
)
reply = chat.choices[0].message.content
print(f"ChatGPT: {reply}")
messages.append({"role": "assistant", "content": reply})
client = OpenAI(api_key="YOUR_API_KEY")
messages = [
{"role": "system", "content": "You are an intelligent assistant."}
]
while True:
message = input("User : ")
if message:
messages.append({"role": "user", "content": message})
chat = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages
)
reply = chat.choices[0].message.content
print(f"ChatGPT: {reply}")
messages.append({"role": "assistant", "content": reply})
❤7😱4
# YT Complete Playlist Download
from pytube import Playlist
p = Playlist("https://www.youtube.com/playlist?list=PLxgZQoSe9cg00xClkch7Gr")
for video in p.videos:
video.streams.first().download()
from pytube import Playlist
p = Playlist("https://www.youtube.com/playlist?list=PLxgZQoSe9cg00xClkch7Gr")
for video in p.videos:
video.streams.first().download()
❤4😢4