Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from langchain_community.chat_models import ChatGooglePalm | |
| from langchain.prompts import PromptTemplate | |
| from langchain.chains import LLMChain, SequentialChain | |
| import os | |
| from dotenv import load_dotenv | |
| def configure(): | |
| load_dotenv() | |
| def generate_game_name_and_functions(type): | |
| os.getenv('GOOGLE_API_KEY') | |
| configure() | |
| llm = ChatGooglePalm(temperature=0.5) | |
| prompt_template_name = PromptTemplate( | |
| input_variables=['type'], | |
| template="I want to build a new, never build before {type} game, Suggest only one fancy and creative name" | |
| ) | |
| name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="game_name") | |
| prompt_template_items = PromptTemplate( | |
| input_variables=['game_name'], | |
| template="You are a Gamer, Write a ten point 'About This Game' {game_name}.Write the general requiremnts for phone and system such as ram and graphic card etc. for this game. And how can we createe this {game_name} game in 10 steps, try to tell a technical person. Tell in bullet points and end every line with double comma" | |
| ) | |
| function_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key='functions') | |
| chain = SequentialChain(chains=[name_chain, function_chain], input_variables=["type"], output_variables=["game_name","functions"]) | |
| response = chain({'type': type}) | |
| game_name = response["game_name"].strip() | |
| functions = response["functions"].strip().split(",,") | |
| functions_formatted = "\n".join([f"- ๐ฎ {item}" for item in functions]) | |
| return f"{game_name}\n\n๐ก About The Game\n\n{functions_formatted}" | |
| iface = gr.Interface( | |
| fn=generate_game_name_and_functions, | |
| inputs="text", | |
| outputs="text", | |
| title="๐ฎ Game Idea Generator ๐ฎ", | |
| description="Generate creative game ideas based on a game type!", | |
| interpretation="markdown" | |
| ) | |
| iface.launch(share=False) |