Skip to content

Commit

Permalink
add image generation action
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamjagga committed Jun 28, 2024
1 parent a52bf90 commit 276049d
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 42 deletions.
Binary file modified fastapi-rest-apis/__pycache__/app.cpython-310.pyc
Binary file not shown.
18 changes: 9 additions & 9 deletions fastapi-rest-apis/actions/scripts/docSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
def find_occurrences(text, keyword):
occurrences = text.lower().count(keyword.lower())
return occurrences

try:
input_json = json.loads(sys.argv[1])
text = input_json["text"]
keyword = input_json["keyword"]
num_occurrences = find_occurrences(text, keyword)
print(json.dumps({"output": {"type": "text", "content": f"The keyword '{keyword}' occurs {num_occurrences} times in the text."}}))
except Exception as e:
print(json.dumps({"output": {"type": "error", "content": e}}))
def get_output():
try:
input_json = json.loads(sys.argv[1])
text = input_json["text"]
keyword = input_json["keyword"]
num_occurrences = find_occurrences(text, keyword)
print(json.dumps({"output": {"type": "text", "content": f"The keyword '{keyword}' occurs {num_occurrences} times in the text."}}))
except Exception as e:
print(json.dumps({"output": {"type": "error", "content": e}}))
11 changes: 11 additions & 0 deletions fastapi-rest-apis/actions/scripts/generateImageFromText.py
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}}))

66 changes: 34 additions & 32 deletions fastapi-rest-apis/actions/scripts/sendEmail.py
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()
28 changes: 28 additions & 0 deletions fastapi-rest-apis/actions/scripts/tweet.py
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}")
14 changes: 14 additions & 0 deletions fastapi-rest-apis/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ async def saveFlowAPI(request: Request):
except:
return False

# response = requests.post(
# f"https://api.stability.ai/v2beta/stable-image/generate/ultra",
# headers={
# "authorization": f"Bearer ",
# "accept": "image/*"
# },
# files={"none": ''},
# data={
# "prompt": "Lighthouse on a cliff overlooking the ocean",
# "output_format": "webp",
# },
# )

# return response.content
# if __name__ == "main":
# uvicorn.run(app, host="127.0.0.1", port=8000)

Expand Down
Binary file modified fastapi-rest-apis/db/__pycache__/index.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion fastapi-rest-apis/db/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os

DB_URL = os.environ['DB_URL']
DB_URL = os.environ['DB_URL']

def createDBSession():
engine = create_engine(DB_URL)
Expand Down

0 comments on commit 276049d

Please sign in to comment.