Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +51 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from langchain.llms import GooglePalm
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
+
from langchain.chains import LLMChain, SequentialChain
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
def configure():
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def generate_game_name_and_functions(type):
|
| 15 |
+
os.getenv('GOOGLE_API_KEY')
|
| 16 |
+
configure()
|
| 17 |
+
|
| 18 |
+
llm = GooglePalm(temperature=0.5)
|
| 19 |
+
|
| 20 |
+
prompt_template_name = PromptTemplate(
|
| 21 |
+
input_variables=['type'],
|
| 22 |
+
template="I want to build a new, never build before {type} game, Suggest only one fancy and creative name"
|
| 23 |
+
)
|
| 24 |
+
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="game_name")
|
| 25 |
+
|
| 26 |
+
prompt_template_items = PromptTemplate(
|
| 27 |
+
input_variables=['game_name'],
|
| 28 |
+
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"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
function_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key='functions')
|
| 32 |
+
|
| 33 |
+
chain = SequentialChain(chains=[name_chain, function_chain], input_variables=["type"], output_variables=["game_name","functions"])
|
| 34 |
+
|
| 35 |
+
response = chain({'type': type})
|
| 36 |
+
|
| 37 |
+
game_name = response["game_name"].strip()
|
| 38 |
+
functions = response["functions"].strip().split(",,")
|
| 39 |
+
functions_formatted = "\n".join([f"🎮 {item}" for item in functions])
|
| 40 |
+
|
| 41 |
+
return f"{game_name}\n\n💡About The Game\n\n{functions_formatted}"
|
| 42 |
+
|
| 43 |
+
iface = gr.Interface(
|
| 44 |
+
fn=generate_game_name_and_functions,
|
| 45 |
+
inputs="text",
|
| 46 |
+
outputs="text",
|
| 47 |
+
title="🎮 Game Idea Generator 🎮",
|
| 48 |
+
description="Generate creative game ideas based on a game type!",
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
iface.launch(share = False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
google.generativeai
|
| 3 |
+
gradio
|