-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a52bf90
commit 276049d
Showing
8 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
fastapi-rest-apis/actions/scripts/generateImageFromText.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def get_output(): | ||
try: | ||
import requests | ||
import json | ||
from craiyon import Craiyon | ||
generator = Craiyon() # Instantiates the api wrapper | ||
result = generator.generate("Photorealistic image of shrek eating earth", negative_prompt="spoon", model_type="art") | ||
print(json.dumps({"output": {"type": "text", "content": f"{result.description}"}})) | ||
except Exception as e: | ||
print(json.dumps({"output": {"type": "error", "content": e}})) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
import requests | ||
import smtplib | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
import os | ||
import json | ||
|
||
def send_email_via_mailchimp(api_key, audience_id, email, content): | ||
url = f"https://us1.api.mailchimp.com/3.0/lists/{audience_id}/members" | ||
headers = { | ||
"Authorization": f"Basic {api_key}", | ||
"Content-Type": "application/json" | ||
} | ||
data = { | ||
"email_address": email, | ||
"status": "subscribed", | ||
"merge_fields": { | ||
"FNAME": "Subscriber", | ||
"LNAME": "Name" | ||
} | ||
} | ||
try: | ||
response = requests.post(url, headers=headers, json=data) | ||
if response.status_code == 200: | ||
print("Email sent successfully!") | ||
else: | ||
print("Failed to send email. Status code:", response.status_code) | ||
except Exception as e: | ||
print("Error sending email:", e) | ||
# Email and password configuration | ||
sender_email = "[email protected]" | ||
receiver_email = "[email protected]" | ||
password = "yaik zgzh zrwr pylj" | ||
|
||
if __name__ == "__main__": | ||
# Specify Mailchimp API key and audience ID | ||
api_key = input("Enter your Mailchimp API key: ") | ||
audience_id = input("Enter your Mailchimp audience ID: ") | ||
# Email content | ||
subject = "Test Email from Python" | ||
body = "Vipul Yamunanagar Wale" | ||
|
||
# Specify recipient email and email content | ||
email = input("Enter recipient email address: ") | ||
content = input("Enter email content: ") | ||
# Create a multipart message and set headers | ||
message = MIMEMultipart() | ||
message["From"] = sender_email | ||
message["To"] = receiver_email | ||
message["Subject"] = subject | ||
|
||
# Send the email | ||
send_email_via_mailchimp(api_key, audience_id, email, content) | ||
# Add body to email | ||
message.attach(MIMEText(body, "plain")) | ||
|
||
try: | ||
# Log in to the SMTP server | ||
server = smtplib.SMTP("smtp.gmail.com", 587) | ||
server.starttls() # Secure the connection | ||
server.login(sender_email, password) | ||
|
||
# Send email | ||
server.sendmail(sender_email, receiver_email, message.as_string()) | ||
json.dumps("Email(s) successfully sent!") | ||
except Exception as e: | ||
json.dumps(f"Error sending email(s): {e}") | ||
finally: | ||
# Quit the SMTP server | ||
server.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
def get_output(): | ||
import tweepy | ||
import json | ||
# Replace these with your own credentials | ||
api_key = "YOUR_API_KEY" | ||
api_secret = "YOUR_API_SECRET" | ||
access_token = "YOUR_ACCESS_TOKEN" | ||
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET" | ||
|
||
# Authenticate to Twitter | ||
auth = tweepy.OAuth1UserHandler(api_key, api_secret, access_token, access_token_secret) | ||
api = tweepy.API(auth) | ||
|
||
# Verify the credentials | ||
try: | ||
api.verify_credentials() | ||
json.dumps("Authentication OK") | ||
except Exception as e: | ||
print(f"Error during authentication: {e}") | ||
|
||
# Create a tweet | ||
tweet = "Hello, world! This is a tweet from Tweepy." | ||
|
||
try: | ||
api.update_status(tweet) | ||
json.dumps("Tweet successfully posted") | ||
except Exception as e: | ||
json.dumps(f"Error: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters