File size: 1,493 Bytes
a9853ee
388ad33
 
 
 
 
a9853ee
 
 
388ad33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9853ee
388ad33
 
a9853ee
388ad33
a9853ee
 
388ad33
 
 
a9853ee
388ad33
 
 
 
a9853ee
 
388ad33
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import gradio as gr
from langchain.chains import LLMChain, SequentialChain
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI

# Set your OpenAI API Key
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")

llm = OpenAI(temperature=0.9)

# Chain 1: Restaurant Name
prompt_template_name = PromptTemplate(
    input_variables=['cuisine'],
    template="I want to open a restaurant for {cuisine} food. Suggest a fancy name for this."
)
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaraunt_name")

# Chain 2: Menu Items
prompt_template_items = PromptTemplate(
    input_variables=['restaraunt_name'],
    template="Suggest me some menu items for {restaraunt_name}."
)
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")

# Combine into SequentialChain
chain = SequentialChain(
    chains=[name_chain, food_items_chain],
    input_variables=['cuisine'],
    output_variables=['restaraunt_name', 'menu_items']
)

# Gradio interface
def generate_restaurant_info(cuisine):
    result = chain({'cuisine': cuisine})
    return result['restaraunt_name'], result['menu_items']

iface = gr.Interface(
    fn=generate_restaurant_info,
    inputs=gr.Textbox(label="Enter Cuisine"),
    outputs=[
        gr.Textbox(label="Restaurant Name"),
        gr.Textbox(label="Menu Items")
    ],
    title="Restaurant & Menu Generator",
    description="Powered by LangChain + OpenAI"
)

iface.launch()