Spaces:
Paused
Paused
| 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) |