Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import openai
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
openai.api_key = '
|
| 7 |
|
|
|
|
| 8 |
def fetch_product_info_and_improve(asin, marketplace):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
'amazon_domain': marketplace,
|
| 12 |
-
'asin': asin,
|
| 13 |
-
'type': 'product'
|
| 14 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
data = api_result.json()
|
| 18 |
|
| 19 |
# Parsing the JSON to extract key details
|
| 20 |
product = data.get("product", {})
|
|
@@ -39,24 +41,22 @@ def fetch_product_info_and_improve(asin, marketplace):
|
|
| 39 |
)
|
| 40 |
improved_output = response.choices[0].text.strip()
|
| 41 |
|
| 42 |
-
except openai.error.
|
| 43 |
-
improved_output =
|
| 44 |
|
| 45 |
return original_output, improved_output
|
| 46 |
|
| 47 |
-
# Streamlit
|
| 48 |
-
st.title(
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
marketplace = st.selectbox("Select Marketplace", ["amazon.co.uk", "amazon.de", "amazon.fr", "amazon.it", "amazon.es", "amazon.nl"])
|
| 53 |
|
| 54 |
-
if st.button(
|
| 55 |
original_output, improved_output = fetch_product_info_and_improve(asin, marketplace)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
st.
|
| 59 |
-
st.write(original_output)
|
| 60 |
|
| 61 |
-
st.
|
| 62 |
-
st.
|
|
|
|
| 1 |
+
import openai
|
| 2 |
import streamlit as st
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
+
# Initialize OpenAI API key
|
| 6 |
+
openai.api_key = 'AsMulA7Q9ShlcsRH8rTZT3BlbkFJ428E8dMNPHjdRzhkEEdW' # Replace with your OpenAI API key
|
| 7 |
|
| 8 |
+
# Define the function to fetch product info and improve the content
|
| 9 |
def fetch_product_info_and_improve(asin, marketplace):
|
| 10 |
+
headers = {
|
| 11 |
+
"x-api-key": "5CCE0A4BA6C546C7987E63B21915AA99", # Replace with your ASIN Data API key
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
+
|
| 14 |
+
response = requests.get(f"https://api_endpoint/{marketplace}/{asin}", headers=headers) # Replace 'api_endpoint' with the actual endpoint URL
|
| 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", {})
|
|
|
|
| 41 |
)
|
| 42 |
improved_output = response.choices[0].text.strip()
|
| 43 |
|
| 44 |
+
except openai.error.OpenaiError as e:
|
| 45 |
+
improved_output = str(e)
|
| 46 |
|
| 47 |
return original_output, improved_output
|
| 48 |
|
| 49 |
+
# Streamlit UI setup
|
| 50 |
+
st.title("Amazon Detail Page Content Improver")
|
| 51 |
|
| 52 |
+
asin = st.text_input("Enter the ASIN:")
|
| 53 |
+
marketplace = st.selectbox("Select the marketplace:", ["US", "UK", "DE", "FR", "IT", "ES"])
|
|
|
|
| 54 |
|
| 55 |
+
if st.button("Fetch and Improve"):
|
| 56 |
original_output, improved_output = fetch_product_info_and_improve(asin, marketplace)
|
| 57 |
|
| 58 |
+
st.write("Original Content:")
|
| 59 |
+
st.text_area("", original_output, height=200)
|
|
|
|
| 60 |
|
| 61 |
+
st.write("Improved Content:")
|
| 62 |
+
st.text_area("", improved_output, height=200)
|