dlaima commited on
Commit
8d71d10
·
verified ·
1 Parent(s): c2ee2ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -1,30 +1,31 @@
1
- import gradio as gr
2
- from langchain.chat_models import ChatOpenAI
3
- from langchain.schema import SystemMessage, HumanMessage
4
-
5
- # Initialize the model
6
- model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
7
-
8
- # Define the PLAN_PROMPT
9
- 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."
10
-
11
- # Function to generate the essay outline
12
- def generate_essay_outline(topic):
13
- messages = [
14
- SystemMessage(content=PLAN_PROMPT),
15
- HumanMessage(content=topic)
16
- ]
17
- response = model.invoke(messages)
18
- return response.content
19
-
20
- # Create Gradio interface
21
- interface = gr.Interface(
22
- fn=generate_essay_outline, # The function to call when the user submits input
23
- inputs="text", # The input is a text field (topic)
24
- outputs="text", # The output is displayed as text (essay outline)
25
- title="Essay Outline Generator", # Optional: Title for the Gradio interface
26
- description="Provide a topic, and the model will generate an essay outline for it.", # Description
27
- )
28
-
29
- # Launch the interface
30
- interface.launch(share=False)
 
 
1
+ import gradio as gr
2
+ from langchain.chat_models import ChatOpenAI
3
+ from langchain.schema import SystemMessage, HumanMessage
4
+
5
+ # Initialize the model
6
+ model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
7
+
8
+ # Define the PLAN_PROMPT
9
+ 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."
10
+
11
+ # Function to generate the essay outline
12
+ def generate_essay_outline(topic):
13
+ messages = [
14
+ SystemMessage(content=PLAN_PROMPT),
15
+ HumanMessage(content=topic)
16
+ ]
17
+ response = model.invoke(messages)
18
+ return response.content
19
+
20
+ # Create Gradio interface
21
+ interface = gr.Interface(
22
+ fn=generate_essay_outline, # The function to call when the user submits input
23
+ inputs="text", # The input is a text field (topic)
24
+ outputs="text", # The output is displayed as text (essay outline)
25
+ title="Essay Outline Generator", # Optional: Title for the Gradio interface
26
+ description="Provide a topic, and the model will generate an essay outline for it.", # Description
27
+ )
28
+
29
+ # Launch the interface
30
+ interface.launch(share=True)
31
+