|
import openai |
|
import gradio as gr |
|
from openai import OpenAI |
|
|
|
|
|
nemotron_api_key = "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" |
|
nemotron_api_url = "https://integrate.api.nvidia.com/v1" |
|
|
|
|
|
client = OpenAI( |
|
base_url=nemotron_api_url, |
|
api_key=nemotron_api_key |
|
) |
|
|
|
|
|
def generate_nemotron_description(product_name, features, audience): |
|
|
|
input_text = ( |
|
f"Write a highly detailed, professional, and attractive product description for a traditional craft item called '{product_name}'. " |
|
f"This product has the following features: {features}. " |
|
f"It is designed for {audience}. Highlight its cultural significance, craftsmanship, uniqueness, and appeal. " |
|
f"Use emotional and sensory-rich language to make it compelling. The description must be at least 300 words long and suitable for e-commerce or marketing." |
|
) |
|
|
|
try: |
|
|
|
completion = client.chat.completions.create( |
|
model="nvidia/nemotron-4-340b-instruct", |
|
messages=[{"role": "user", "content": input_text}], |
|
temperature=0.7, |
|
top_p=0.9, |
|
max_tokens=250, |
|
stream=False |
|
) |
|
|
|
|
|
|
|
generated_text = completion.choices[0].message.content |
|
return generated_text.strip() |
|
|
|
except Exception as e: |
|
return f"An error occurred: {str(e)}" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_nemotron_description, |
|
inputs=[ |
|
gr.Textbox(label="Product Name", placeholder="e.g., Handwoven Silk Saree"), |
|
gr.Textbox(label="Features", placeholder="e.g., eco-friendly, handmade, intricate patterns"), |
|
gr.Textbox(label="Target Audience", placeholder="e.g., luxury buyers, art enthusiasts"), |
|
], |
|
outputs=gr.Textbox(label="Detailed Product Description"), |
|
title="AI Product Description Generator (Nemotron)", |
|
description=( |
|
"Generate long, engaging, and highly detailed product descriptions using Nemotron's API. " |
|
"Perfect for traditional craft items, e-commerce listings, and marketing purposes." |
|
), |
|
flagging_mode="never" |
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|