Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from langchain.chains import LLMChain, SequentialChain
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from langchain.llms import OpenAI
|
| 5 |
+
|
| 6 |
+
# Define the LLM
|
| 7 |
+
llm = OpenAI(temperature=0.9)
|
| 8 |
+
|
| 9 |
+
# Chain 1: Restaurant Name
|
| 10 |
+
prompt_template_name = PromptTemplate(
|
| 11 |
+
input_variables=['cuisine'],
|
| 12 |
+
template="I want to open a restaurant for {cuisine} food. Suggest a fancy name for this."
|
| 13 |
+
)
|
| 14 |
+
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaraunt_name")
|
| 15 |
+
|
| 16 |
+
# Chain 2: Menu Items
|
| 17 |
+
prompt_template_items = PromptTemplate(
|
| 18 |
+
input_variables=['restaraunt_name'],
|
| 19 |
+
template="Suggest me some menu items for {restaraunt_name}."
|
| 20 |
+
)
|
| 21 |
+
food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")
|
| 22 |
+
|
| 23 |
+
# Combine into SequentialChain
|
| 24 |
+
chain = SequentialChain(
|
| 25 |
+
chains=[name_chain, food_items_chain],
|
| 26 |
+
input_variables=['cuisine'],
|
| 27 |
+
output_variables=['restaraunt_name', 'menu_items'],
|
| 28 |
+
verbose=True
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Gradio Function
|
| 32 |
+
def generate_restaurant_info(cuisine):
|
| 33 |
+
output = chain({'cuisine': cuisine})
|
| 34 |
+
return output['restaraunt_name'], output['menu_items']
|
| 35 |
+
|
| 36 |
+
# Gradio UI
|
| 37 |
+
iface = gr.Interface(
|
| 38 |
+
fn=generate_restaurant_info,
|
| 39 |
+
inputs=gr.Textbox(label="Enter Cuisine (e.g., Italian, Japanese, Indian)"),
|
| 40 |
+
outputs=[
|
| 41 |
+
gr.Textbox(label="Restaurant Name"),
|
| 42 |
+
gr.Textbox(label="Menu Items")
|
| 43 |
+
],
|
| 44 |
+
title="Restaurant Name & Menu Generator",
|
| 45 |
+
description="Enter a cuisine type, and get a fancy restaurant name and menu ideas using LangChain + OpenAI."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
iface.launch()
|