SaiLochana commited on
Commit
307cd56
1 Parent(s): aae3779

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +69 -0
  2. prompt_template.txt +12 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import os, openai
3
+ from langchain.prompts import PromptTemplate
4
+ from langchain.chat_models import ChatOpenAI
5
+ from typing import Any
6
+ from langchain.base_language import BaseLanguageModel
7
+ from langchain.chains.llm import LLMChain
8
+ import gradio as gr
9
+
10
+ # OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
11
+ OPENAI_API_KEY='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'
12
+ prompt_file = "prompt_template.txt"
13
+
14
+
15
+ class ProductDescGen(LLMChain):
16
+ """LLM Chain specifically for generating multi paragraph rich text product description using emojis."""
17
+
18
+ @classmethod
19
+ def from_llm(
20
+ cls, llm: BaseLanguageModel, prompt: str, **kwargs: Any
21
+ ) -> ProductDescGen:
22
+ """Load ProductDescGen Chain from LLM."""
23
+ return cls(llm=llm, prompt=prompt, **kwargs)
24
+
25
+
26
+ def product_desc_generator(product_name, keywords):
27
+ with open(prompt_file, "r") as file:
28
+ prompt_template = file.read()
29
+
30
+ PROMPT = PromptTemplate(
31
+ input_variables=["product_name", "keywords"], template=prompt_template
32
+ )
33
+ llm = ChatOpenAI(
34
+ model_name="gpt-3.5-turbo",
35
+ temperature=0.7,
36
+ openai_api_key=OPENAI_API_KEY,
37
+ )
38
+
39
+ ProductDescGen_chain = ProductDescGen.from_llm(llm=llm, prompt=PROMPT)
40
+ ProductDescGen_query = ProductDescGen_chain.apply_and_parse(
41
+ [{"product_name": product_name, "keywords": keywords}]
42
+ )
43
+ return ProductDescGen_query[0]["text"]
44
+
45
+
46
+ with gr.Blocks() as demo:
47
+ gr.HTML("""<h1>Product Description Enhancer</h1>""")
48
+ gr.Markdown(
49
+ "Generate Product Description for your products instantly!<br>"
50
+ "Provide product name and keywords related to that product. Click on 'Generate Description' button and multi-paragraph rich text product description will be genrated instantly.<br>"
51
+ "Note: Generated product description is SEO compliant and can be used to populate product information."
52
+ )
53
+
54
+ with gr.Tab("Generate Product Description!"):
55
+ product_name = gr.Textbox(
56
+ label="Product Name",
57
+ placeholder="Nike Shoes",
58
+ )
59
+ keywords = gr.Textbox(
60
+ label="Keywords (separated by commas)",
61
+ placeholder="black shoes, leather shoes for men, water resistant",
62
+ )
63
+ product_description = gr.Textbox(label="Product Description")
64
+ click_button = gr.Button(value="Generate Description!")
65
+ click_button.click(
66
+ product_desc_generator, [product_name, keywords], product_description
67
+ )
68
+
69
+ demo.launch()
prompt_template.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """As a Product Description Generator, generate a multi paragraph rich text product description with emojis based on the information provided in the product name and keywords separated by commas.
2
+
3
+ Example Format:
4
+ PRODUCT NAME: product name here
5
+ KEYWORDS: keywords separated by commas here
6
+ PRODUCT DESCRIPTION: product description here
7
+
8
+ Generate a product description that is creative and SEO compliant. Emojis should be added to make product description look appealing. Begin!
9
+
10
+ PRODUCT NAME: {product_name}
11
+ KEYWORDS: {keywords}
12
+ PRODUCT DESCRIPTION:"""
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ langchain
2
+ openai
3
+ gradio