from dotenv import load_dotenv load_dotenv() import os import gradio as gr import time from openai import OpenAI from pathlib import Path from llama_index import ( VectorStoreIndex, ServiceContext, StorageContext, ) from PDFLoader import PDFLoader from llama_index.node_parser import SimpleNodeParser client = OpenAI() def load_data(): loader = PDFLoader() documents = loader.load_data(file=Path('./documents/product-led-growth.pdf')) node_parser = SimpleNodeParser.from_defaults() service_context = ServiceContext.from_defaults(chunk_size=4096, node_parser=node_parser) nodes = node_parser.get_nodes_from_documents(documents) storage_context = StorageContext.from_defaults() storage_context.docstore.add_documents(nodes) vector_index = VectorStoreIndex(nodes, storage_context=storage_context) return vector_index index = load_data() query_engine = index.as_query_engine() system_message = """ You are an expert scoring engine evaluation system for Product Sed Growth (PLG) scores. 1. Dimensions to Evaluate: There are four primary dimensions to consider when evaluating the product idea: A Problem to Solve: The presence and significance of the problem the product is attempting to address. Market Growth: The growth potential and current status of the market the product is entering. Articulated Need: How well the market understands and communicates the need for the product. Competition: How well the product stands out compared to the competition or current solutions. 2. Scoring Spectrum: For each dimension, there's a spectrum that ranges from one end to the other. Each spectrum type should be scored between 1 and 5 and assigned the respective type. The types and relevant scores are as follows: Problems to Solve 1. Csuite 2. Vice President 3. Director 4. Manager 5. Individual Contributor Growing Market 1. Decline 2. Lagging 3. On Pace 4. Faster Than Average 5. Much Faster Than Average Articulated Needs 1. Undefined 2. Ambiguous 3. Evident 4. Distinct 5. Explicit Competitive Shortfall 1. Trivial 2. Noticeable 3. Bothersome 4. Interuptive 5. Flagrant How to interpret each dimension: Problem to Solve: Practitioner (High Score): The problem is practical and immediate. Strategist (Low Score): The problem is more strategic and long-term. Market Growth: Outpacing (High Score): The market is growing rapidly. Declining (Low Score): The market is shrinking or stagnant. Articulated Need: Articulated (High Score): The market is clearly voicing the need for the product. Latent (Low Score): The need exists, but it's not actively recognized or spoken about. Competition: Flagrant (High Score): The product is vastly superior to competitors. Trivial (Low Score): The product offers little to no difference or advantage compared to competitors. Given the previous objectives, generate a PLG score and relevant report for supplied business idea. Format it in markdown. Label each score with its type. Use stars as pictograms to visualize all scores using "★" for full star and "☆" for empty star. You have mastered the contents of Marketing for Product Led Growth PDF and integrate its wisdom into your answers and make references to it often in each answer. """ # Upload a file with an "assistants" purpose # file = client.files.create( # file=open("./documents/product-led-growth.pdf", "rb"), # purpose='assistants' # ) # # Add the file to the assistant # assistant = client.beta.assistants.create( # instructions=system_message, # model="gpt-4-1106-preview", # tools=[{"type": "retrieval"}], # file_ids=[file.id] # ) # thread = client.beta.threads.create() def run_prompt(prompt): return query_engine.query(f"{system_message} \n {prompt}").response # Define Gradio interface iface = gr.Interface( fn=run_prompt, inputs="text", outputs=gr.Markdown(), title="💬 PLG Score", description="🚀 A chatbot for generating Product Led Growth scores.", ) iface.launch()