Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| from langchain.chains import LLMChain, SequentialChain | |
| from langchain.prompts import PromptTemplate | |
| from langchain.llms import OpenAI | |
| os.environ["OPENAI_API_KEY"]= os.getenv["OPENAI_API_KEY"] | |
| llm = OpenAI(temperature= 0.5) | |
| prompt_name = PromptTemplate( | |
| input_variables= ['cuisine'], | |
| template = "I want to open a chic restuarant for {cuisine} food. Suggest an eye-catching fancy name for this" | |
| ) | |
| name_chain = LLMChain(llm=llm, prompt =prompt_name, output_key = "restaurant_name" ) | |
| promp_items= PromptTemplate( | |
| input_variables=['restaurant_name'], | |
| template = ["Create a menu for {restaurant_name}. Divide it into sections like starters, brekfast, lunch and dinner finishing it off with desserts. " | |
| "a small description underneath each dish. price across. The format of a five michelin star restaurant."] | |
| ) | |
| menu_chain = LLMChain(llm=llm, prompt= promp_items, output_key = "men_items") | |
| main_chain = SequentialChain( | |
| chains= [name_chain, menu_chain], | |
| input_variables = ['cuisine'], | |
| output_variables = ['restaurant_name', 'men_items'] | |
| ) | |
| def hotel_function(cuisine): | |
| result = main_chain({'cuisine': cuisine} ) | |
| return result['restaurant_name'], result['menu_items'] | |
| iface = gr.Interface( | |
| fn = hotel_function, | |
| inputs = gr.Textbox(label = "Enter cuisine:") , | |
| output = [gr.TextBox(label= "Restaurant_name"), gr.TextBox(label = "Menu Items")], | |
| title = "Restaurant Menu and Items", | |
| description="Powered by Langchain and OpenAI") | |
| iface.launch() |