File size: 2,012 Bytes
9e270ae
 
9bad7dc
9e270ae
9bad7dc
 
9e270ae
 
9bad7dc
 
 
 
 
 
9e270ae
9bad7dc
 
9e270ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9bad7dc
 
9e270ae
9bad7dc
9e270ae
9bad7dc
 
 
9e270ae
e12b949
9e270ae
9bad7dc
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import requests
import openai

# Set your OpenAI API Key
openai.api_key = 'AsMulA7Q9ShlcsRH8rTZT3BlbkFJ428E8dMNPHjdRzhkEEdW'

def fetch_product_info_and_improve(asin, marketplace):
    # Parameters for ASIN Data API
    params = {
        'api_key': '5CCE0A4BA6C546C7987E63B21915AA99',
        'amazon_domain': marketplace,
        'asin': asin,
        'type': 'product'
    }
    api_result = requests.get('https://api.asindataapi.com/request', params)
    data = api_result.json()

    # Parsing the JSON to extract key details
    product = data.get("product", {})
    product_title = product.get("title", "N/A")
    description = product.get("description", "N/A")
    bullet_points = product.get("feature_bullets_flat", "N/A")

    prompt_text = (f"Based on the provided Amazon detail page content, please improve the following:\n"
                   f"(i) Product Title: {product_title}\n"
                   f"(ii) Product Description: {description}\n"
                   f"(iii) Bullet Points: {bullet_points}\n"
                   f"\nPlease provide a revised (i) title, (ii) description, and (iii) bullet points.")
    
    try:
        response = openai.Completion.create(
            engine="davinci",
            prompt=prompt_text,
            max_tokens=300
        )
        improved_output = response.choices[0].text.strip()

    except openai.error.AuthenticationError:
        improved_output = "Error occurred with OpenAI. Please check your API key."

    return product_title + "\n" + description + "\n" + bullet_points, improved_output

st.title("Amazon Product Detail Page Enhancer")
asin = st.text_input("Enter ASIN:")
marketplace = st.text_input("Enter Marketplace (e.g., amazon.com, amazon.it, etc.):")

if st.button("Fetch and Improve"):
    original_output, improved_output = fetch_product_info_and_improve(asin, marketplace)
    st.subheader("Original Details:")
    st.write(original_output)
    st.subheader("Improved Details:")
    st.write(improved_output)