Spaces:
Runtime error
Runtime error
File size: 1,851 Bytes
fce0a4a |
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 51 |
import gradio as gr
from langchain.llms import GooglePalm
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 = GooglePalm(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!",
)
iface.launch(share = False) |