Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,20 @@
|
|
| 1 |
-
import openai
|
| 2 |
import streamlit as st
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
openai.api_key = 'AsMulA7Q9ShlcsRH8rTZT3BlbkFJ428E8dMNPHjdRzhkEEdW'
|
| 7 |
|
| 8 |
-
# Define the function to fetch product info and improve the content
|
| 9 |
def fetch_product_info_and_improve(asin, marketplace):
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if response.status_code != 200:
|
| 17 |
-
return "Error fetching product info.", "N/A"
|
| 18 |
-
|
| 19 |
-
data = response.json()
|
| 20 |
|
| 21 |
# Parsing the JSON to extract key details
|
| 22 |
product = data.get("product", {})
|
|
@@ -24,9 +22,6 @@ def fetch_product_info_and_improve(asin, marketplace):
|
|
| 24 |
description = product.get("description", "N/A")
|
| 25 |
bullet_points = product.get("feature_bullets_flat", "N/A")
|
| 26 |
|
| 27 |
-
original_output = f"Product Title: {product_title}\nDescription: {description}\nBullet Points: {bullet_points}"
|
| 28 |
-
|
| 29 |
-
# Improve the content with OpenAI
|
| 30 |
prompt_text = (f"Based on the provided Amazon detail page content, please improve the following:\n"
|
| 31 |
f"(i) Product Title: {product_title}\n"
|
| 32 |
f"(ii) Product Description: {description}\n"
|
|
@@ -41,22 +36,18 @@ def fetch_product_info_and_improve(asin, marketplace):
|
|
| 41 |
)
|
| 42 |
improved_output = response.choices[0].text.strip()
|
| 43 |
|
| 44 |
-
except openai.error.
|
| 45 |
-
improved_output =
|
| 46 |
-
|
| 47 |
-
return original_output, improved_output
|
| 48 |
|
| 49 |
-
|
| 50 |
-
st.title("Amazon Detail Page Content Improver")
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
if st.button("Fetch and Improve"):
|
| 56 |
original_output, improved_output = fetch_product_info_and_improve(asin, marketplace)
|
| 57 |
-
|
| 58 |
-
st.write(
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
st.write("Improved Content:")
|
| 62 |
-
st.text_area("", improved_output, height=200)
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
import openai
|
| 4 |
|
| 5 |
+
# Set your OpenAI API Key
|
| 6 |
+
openai.api_key = 'AsMulA7Q9ShlcsRH8rTZT3BlbkFJ428E8dMNPHjdRzhkEEdW'
|
| 7 |
|
|
|
|
| 8 |
def fetch_product_info_and_improve(asin, marketplace):
|
| 9 |
+
# Parameters for ASIN Data API
|
| 10 |
+
params = {
|
| 11 |
+
'api_key': '5CCE0A4BA6C546C7987E63B21915AA99',
|
| 12 |
+
'amazon_domain': marketplace,
|
| 13 |
+
'asin': asin,
|
| 14 |
+
'type': 'product'
|
| 15 |
}
|
| 16 |
+
api_result = requests.get('https://api.asindataapi.com/request', params)
|
| 17 |
+
data = api_result.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Parsing the JSON to extract key details
|
| 20 |
product = data.get("product", {})
|
|
|
|
| 22 |
description = product.get("description", "N/A")
|
| 23 |
bullet_points = product.get("feature_bullets_flat", "N/A")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
prompt_text = (f"Based on the provided Amazon detail page content, please improve the following:\n"
|
| 26 |
f"(i) Product Title: {product_title}\n"
|
| 27 |
f"(ii) Product Description: {description}\n"
|
|
|
|
| 36 |
)
|
| 37 |
improved_output = response.choices[0].text.strip()
|
| 38 |
|
| 39 |
+
except openai.error.AuthenticationError:
|
| 40 |
+
improved_output = "Error occurred with OpenAI. Please check your API key."
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
return product_title + "\n" + description + "\n" + bullet_points, improved_output
|
|
|
|
| 43 |
|
| 44 |
+
st.title("Amazon Product Detail Page Enhancer")
|
| 45 |
+
asin = st.text_input("Enter ASIN:")
|
| 46 |
+
marketplace = st.text_input("Enter Marketplace (e.g., amazon.com, amazon.it, etc.):")
|
| 47 |
|
| 48 |
if st.button("Fetch and Improve"):
|
| 49 |
original_output, improved_output = fetch_product_info_and_improve(asin, marketplace)
|
| 50 |
+
st.subheader("Original Details:")
|
| 51 |
+
st.write(original_output)
|
| 52 |
+
st.subheader("Improved Details:")
|
| 53 |
+
st.write(improved_output)
|
|
|
|
|
|