<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lokesh Velayudham - lowkeyy.eth</title>
    <description>The latest articles on DEV Community by Lokesh Velayudham - lowkeyy.eth (@lokeshvelayudham).</description>
    <link>https://dev.to/lokeshvelayudham</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1130659%2F78c12209-4d8b-4218-867f-9dea4c661c47.jpeg</url>
      <title>DEV Community: Lokesh Velayudham - lowkeyy.eth</title>
      <link>https://dev.to/lokeshvelayudham</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lokeshvelayudham"/>
    <language>en</language>
    <item>
      <title>Flask(Python) + CRUD ( Postman) +MongoDB + Docker</title>
      <dc:creator>Lokesh Velayudham - lowkeyy.eth</dc:creator>
      <pubDate>Thu, 10 Aug 2023 15:23:43 +0000</pubDate>
      <link>https://dev.to/lokeshvelayudham/flaskpython-crud-postman-mongodb-docker-2n7c</link>
      <guid>https://dev.to/lokeshvelayudham/flaskpython-crud-postman-mongodb-docker-2n7c</guid>
      <description>&lt;p&gt;An application on pyhton- flask framework, for CRUD operations test it using postman application and use monogodb to access and delete the data and dockerize the application&lt;/p&gt;

&lt;p&gt;An appliction for CRUD operations on MongoDB using flask+python backend and build  REST API, The REST API endpoints should be accessible via HTTP requests and tested using Postman.&lt;/p&gt;

&lt;p&gt;The application should connect to a MongoDB database.&lt;br&gt;
The application should provide the following REST API endpoints:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-1.GET /users - Returns a list of all users.
-2.GET /users/&amp;lt;id&amp;gt; - Returns the user with the specified ID.
-3.POST /users - Creates a new user with the specified data.
-4.PUT /users/&amp;lt;id&amp;gt; - Updates the user with the specified ID with the new data.
-5.DELETE /users/&amp;lt;id&amp;gt; - Deletes the user with the specified ID.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Setup and installation
1. Create a virtual environment 
   1.  ```

python3 -m venv venv

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt; &lt;code&gt;

source venv/bin/activate

&lt;/code&gt;
3.  create a new file in the directoty named app.py &lt;/li&gt;
&lt;/ol&gt;

&lt;ol&gt;
&lt;li&gt; To install Flask and pyMongo using &lt;strong&gt;pip install&lt;/strong&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;

pip install Flask pymongo

&lt;/code&gt;
2.  import the flask and pymongo into the app.py
```
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;App.py: &lt;a href="https://github.com/lokeshvelayudham/corider_assignment"&gt;https://github.com/lokeshvelayudham/corider_assignment&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import flask and pyMongo, bson
from bson import ObjectId
from flask import Flask, jsonify, request
from flask_pymongo import PyMongo


app = Flask(__name__)

# Configure the Flask app to connect to your MongoDB database
app.config['MONGO_URI'] = 'mongodb://localhost:27017/corider'
mongo = PyMongo(app)

# Define the User collection
users = mongo.db.users


# GET /users - Returns a list of all users.
@app.route('/users', methods=['GET'])
def get_all_users():
    user_list = []
    for user in users.find():
        user_list.append({
            'id': str(user['_id']),
            'name': user['name'],
            'email': user['email']
        })
    return jsonify(user_list)



# GET /users/&amp;lt;id&amp;gt; - Returns the user with the specified ID.
@app.route('/users/&amp;lt;id&amp;gt;', methods=['GET'])
def get_user(id):
    user = users.find_one_or_404({'_id': ObjectId(id)})
    return jsonify({
        'id': str(user['_id']),
        'name': user['name'],
        'email': user['email']
    })


# POST /users - Creates a new user with the specified data.
@app.route('/users', methods=['POST'])
def create_user():
    data = request.get_json()
    user_id = users.insert_one(data).inserted_id
    return jsonify({'message': 'User created successfully', 'id': str(user_id)})


# PUT /users/&amp;lt;id&amp;gt; - Updates the user with the specified ID with the new data.
@app.route('/users/&amp;lt;id&amp;gt;', methods=['PUT'])
def update_user(id):
    data = request.get_json()
    users.update_one({'_id': ObjectId(id)}, {'$set': data})
    return jsonify({'message': 'User updated successfully'})


# DELETE /users/&amp;lt;id&amp;gt; - Deletes the user with the specified ID.
@app.route('/users/&amp;lt;id&amp;gt;', methods=['DELETE'])
def delete_user(id):
    users.delete_one({'_id': ObjectId(id)})
    return jsonify({'message': 'User deleted successfully'})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install &amp;amp; Setup MongoDb Databsae using &lt;strong&gt;homebrew&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;install MongoDb community in the local
1.

&lt;code&gt;brew install mongodb-community@6.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To Start mongoDb server 
1.

&lt;code&gt;brew services start mongodb-community@6.0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After starting the server open a new terminal
1.

&lt;code&gt;mongo&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;br&gt;
&lt;code&gt;use Collection&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To insert the data into the db&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```db.users.insert({
    "name": "John Doe",
    "email": "john@example.com",
    "password": "secretpassword"
    })```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  To Test :
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Testing the Application using CRUD

&lt;ol&gt;
&lt;li&gt;Test in the POSTMAN&lt;/li&gt;
&lt;li&gt;install postman desktop agent

&lt;ol&gt;
&lt;li&gt;The REST API endpoints:

&lt;ol&gt;
&lt;li&gt;GET /users - Returns a list of all users.&lt;/li&gt;
&lt;li&gt;GET /users/ - Returns the user with the specified ID.&lt;/li&gt;
&lt;li&gt;POST /users - Creates a new user with the specified data.&lt;/li&gt;
&lt;li&gt;PUT /users/ - Updates the user with the specified ID with the new data.&lt;/li&gt;
&lt;li&gt;DELETE /users/ - Deletes the user with the specified ID.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  To dockerize :
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a file named Dockerfile&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;requirements.txt&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flask-PyMongo==2.3.0```

3. create a yml file
4. Build and run 
docker-compose build
docker-compose up
5. push the docker into hub
1. list the docker images -

``` docker images```

2. login into docker -

```docker login```

enter username and password
3. create a image tag docker tag IMAGE NAME HUBNAME/IMAGE NAME -

```docker tag corider_assignment-app lokeshbx/corider_assignment-app```

4. docker push IMAGE - docker push lokeshbx/corider_assignment-app 
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the official Python image as the base image
FROM python:3.8

# Set environment variables for Flask
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0

# Set up a working directory
WORKDIR /Users/lokesh/Downloads/2022/web2/corider_assignment

# Copy requirements file and install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code into the container
COPY . .

# Expose the port that the application runs on
EXPOSE 5000

# Run the application
CMD ["flask", "run"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aoRWyt_E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31lr21ho41i6htap8usr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aoRWyt_E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31lr21ho41i6htap8usr.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;video : &lt;a href="https://youtu.be/SlQMuN_IvRY"&gt;https://youtu.be/SlQMuN_IvRY&lt;/a&gt;&lt;br&gt;
Docker :&lt;a href="https://hub.docker.com/repository/docker/lokeshbx/corider_assignment-app/general"&gt;https://hub.docker.com/repository/docker/lokeshbx/corider_assignment-app/general&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Ultimate Guide to Enhancing Your Sales with Stable Diffusion API and Printfy API</title>
      <dc:creator>Lokesh Velayudham - lowkeyy.eth</dc:creator>
      <pubDate>Tue, 01 Aug 2023 11:34:12 +0000</pubDate>
      <link>https://dev.to/lokeshvelayudham/the-ultimate-guide-to-enhancing-your-sales-with-stable-diffusion-api-and-printfy-api-3c31</link>
      <guid>https://dev.to/lokeshvelayudham/the-ultimate-guide-to-enhancing-your-sales-with-stable-diffusion-api-and-printfy-api-3c31</guid>
      <description>&lt;p&gt;Using a stable diffusion api and printfy api: Breaking Down the Process&lt;/p&gt;

&lt;p&gt;Github. : &lt;a href="https://github.com/lokeshvelayudham/stability-printfyapiAi"&gt;https://github.com/lokeshvelayudham/stability-printfyapiAi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more connect with me @ &lt;a href="https://www.linkedin.com/in/lokeshvelayudham/"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aOhqdf-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mxqketyp5kvpcsv9p7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aOhqdf-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mxqketyp5kvpcsv9p7c.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're in the world of AI, you've probably heard of Stable&lt;br&gt;
diffusion . It's a powerful tool that transforms text into high-resolution, high-quality images. With an easy-to-use platform and a dynamic user community, it's become a standout tool in the digital landscape.&lt;/p&gt;

&lt;p&gt;Use Stable diffusion ai to generate image and use printfy api to publish it in the printfy - shopify store&lt;/p&gt;

&lt;p&gt;The Stable diffusion offers an API to generate an text to Image generative AI, Where the images are stored in locally/ MongoDB and those images are uploaded to the store using printfy api &lt;/p&gt;

&lt;p&gt;To Generate an Image, We are using Stability diffusion - &lt;br&gt;
We will be requiring open API key and Stability diffusion AI key &lt;br&gt;
function to generate an Images and stored &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oz_GNyUa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d51r9a6typiyw86l9nbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oz_GNyUa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d51r9a6typiyw86l9nbn.png" alt="Image description" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;`for idx, row in tqdm(df.iterrows(), total=df.shape[0]):&lt;br&gt;
    detail = row['details']&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Generate the title, description, prompt, and tags using the OpenAI API
title = generate_clickable_title(detail)
description = generate_description(detail)
image_prompt = generate_image_prompt(detail)
tag = generate_tags(detail)



# Generate the image using the Stability.ai API
url = "https://api.stability.ai/v1/generation/stable-diffusion-v1-5/text-to-image"
headers = {"Authorization": f"Bearer {stability_ai_key}", "Accept": "image/png"}
data = {
    "width": 512,
    "height": 512,
    "text_prompts": [
        {
            "text": image_prompt,
            "weight": 0.5
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
image_data = response.content
image = Image.open(io.BytesIO(image_data))
file_name = f"image_{idx}.png"  
local_path = f"{file_name}"  # Save the image in the same directory
image.save(local_path)

# Append the generated data to the lists
file_names.append(file_name)
local_paths.append(local_path)
titles.append(title)
descriptions.append(description)
tags.append(tag)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  TO Upload product to the shopify-printify website
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YGxvlKTu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sis0cym40ffzwqpfo79e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YGxvlKTu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sis0cym40ffzwqpfo79e.png" alt="Image description" width="600" height="200"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# To change the print object, use this to find the variant id curl -X GET "https://api.printify.com/v1/catalog/blueprints/1098/print_providers/228/variants.json" "Authorization: Bearer {access token}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Find your shop ID by running this: curl -X GET &lt;a href="https://api.printify.com/v1/shops.json"&gt;https://api.printify.com/v1/shops.json&lt;/a&gt; --header "Authorization: Bearer {access token}"
&lt;/h1&gt;

&lt;p&gt;`For idx, row in image_df.iterrows():&lt;br&gt;
    # Convert the image to Base64&lt;br&gt;
    with open(row['local_path'], "rb") as img_file:&lt;br&gt;
        img_b64 = base64.b64encode(img_file.read()).decode('utf-8')&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Upload the image to the Printify media library
data = {
    "file_name": row['file_name'],
    "contents": img_b64
}
response = requests.post(upload_url, headers=headers, json=data)
image_id = response.json()["id"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;# Current settings are for wall art&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create the product with the uploaded image
data = {
    "title": row['title'],
    "description": row['description'],
    "tags": row['tags'].split(', '),  # Assuming tags are comma-separated in the CSV
    "blueprint_id": 6,  # Replace with the actual blueprint ID
    "print_provider_id": 270,
    "variants": [
        {
            "id": 12126,  # Replace with the actual variant ID
            "price": 3999,
            "is_enabled": True
        }
    ],
    "print_areas": [
        {
            "variant_ids": [82064],  # Replace with the actual variant ID
            "placeholders": [
                {
                    "position": "front",
                    "height": 3761,
                    "width": 3319,
                    "images": [
                        {
                            "id": image_id,
                            "x": 0.5,
                            "y": 0.5,
                            "scale": 1.5,
                            "angle": 0
                        }
                    ]
                }
            ]
        }
    ]
}
response = requests.post(product_url, headers=headers, json=data)
if response.status_code &amp;gt;= 200 and response.status_code &amp;lt; 300:
    print(f"Product {idx+1} created successfully!")
else:
    print(f"Failed to create product {idx+1}. Server responded with: {response.text}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>python</category>
      <category>openai</category>
      <category>stablediffusio</category>
    </item>
  </channel>
</rss>
