heliosbrahma commited on
Commit
407877b
1 Parent(s): d6ccd5c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +68 -0
  2. prompt_template.txt +12 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ prompt_file = "prompt_template.txt"
12
+
13
+
14
+ class ProductDescGen(LLMChain):
15
+ """LLM Chain specifically for generating multi paragraph rich text product description using emojis."""
16
+
17
+ @classmethod
18
+ def from_llm(
19
+ cls, llm: BaseLanguageModel, prompt: str, **kwargs: Any
20
+ ) -> ProductDescGen:
21
+ """Load ProductDescGen Chain from LLM."""
22
+ return cls(llm=llm, prompt=prompt, **kwargs)
23
+
24
+
25
+ def product_desc_generator(product_name, keywords):
26
+ with open(prompt_file, "r") as file:
27
+ prompt_template = file.read()
28
+
29
+ PROMPT = PromptTemplate(
30
+ input_variables=["product_name", "keywords"], template=prompt_template
31
+ )
32
+ llm = ChatOpenAI(
33
+ model_name="gpt-3.5-turbo",
34
+ temperature=0.7,
35
+ openai_api_key=OPENAI_API_KEY,
36
+ )
37
+
38
+ ProductDescGen_chain = ProductDescGen.from_llm(llm=llm, prompt=PROMPT)
39
+ ProductDescGen_query = ProductDescGen_chain.apply_and_parse(
40
+ [{"product_name": product_name, "keywords": keywords}]
41
+ )
42
+ return ProductDescGen_query[0]["text"]
43
+
44
+
45
+ with gr.Blocks() as demo:
46
+ gr.HTML("""<h1>Welcome to Product Description Generator</h1>""")
47
+ gr.Markdown(
48
+ "Generate Product Description for your products instantly!<br>"
49
+ "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>"
50
+ "Note: Generated product description is SEO compliant and can be used to populate product information."
51
+ )
52
+
53
+ with gr.Tab("Generate Product Description!"):
54
+ product_name = gr.Textbox(
55
+ label="Product Name",
56
+ placeholder="Nike Shoes",
57
+ )
58
+ keywords = gr.Textbox(
59
+ label="Keywords (separated by commas)",
60
+ placeholder="black shoes, leather shoes for men, water resistant",
61
+ )
62
+ product_description = gr.Textbox(label="Product Description")
63
+ click_button = gr.Button(value="Generate Description!")
64
+ click_button.click(
65
+ product_desc_generator, [product_name, keywords], product_description
66
+ )
67
+
68
+ 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