File size: 1,184 Bytes
8d71d10
0eeb585
 
8d71d10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)