import gradio as gr #from langchain.chat_models import ChatOpenAI from langchain_openai import ChatOpenAI from langchain.schema import SystemMessage, HumanMessage # Initialize the model model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0) # Define the PLAN_PROMPT PLAN_PROMPT = "You are an expert writer tasked with writing a high-level outline of a short 3-paragraph essay. Write such an outline for the user-provided topic." # Function to generate the essay outline def generate_essay_outline(topic): messages = [ SystemMessage(content=PLAN_PROMPT), HumanMessage(content=topic) ] response = model.invoke(messages) return response.content # Create Gradio interface interface = gr.Interface( fn=generate_essay_outline, # The function to call when the user submits input inputs="text", # The input is a text field (topic) outputs="text", # The output is displayed as text (essay outline) title="Essay Outline Generator", # Optional: Title for the Gradio interface description="Provide a topic, and the model will generate an essay outline for it.", # Description ) # Launch the interface interface.launch(share=True)