fixes
This commit is contained in:
parent
d93ad42c76
commit
8bb26cca49
1 changed files with 9 additions and 51 deletions
|
|
@ -1,37 +1,11 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import streamlit as st
|
|
||||||
from browser_use import Agent, SystemPrompt
|
from browser_use import Agent, SystemPrompt
|
||||||
|
from langchain_google_genai import ChatGoogleGenerativeAI
|
||||||
|
from langchain_openai import ChatOpenAI
|
||||||
from langchain_anthropic import ChatAnthropic
|
from langchain_anthropic import ChatAnthropic
|
||||||
|
|
||||||
def create_ui() -> tuple[str, str]:
|
async def generate_meme(query: str) -> None:
|
||||||
st.title("🎭 AI Meme Generator with Browser Use")
|
api_key = "sk-A" # Replace with your actual DeepSeek API key
|
||||||
|
|
||||||
# Sidebar for API key
|
|
||||||
with st.sidebar:
|
|
||||||
st.header("Configuration")
|
|
||||||
api_key = st.text_input("Enter your Anthropic API Key:", type="password")
|
|
||||||
|
|
||||||
# Main content
|
|
||||||
st.info("""
|
|
||||||
🤖 This browser agent will help you generate loads of memes by going to imgflip.com and searching for the perfect template for your given query.
|
|
||||||
""")
|
|
||||||
|
|
||||||
query = st.text_input(
|
|
||||||
"What would you like to generate a meme for?",
|
|
||||||
placeholder="Example: India losing against New Zealand in the final of the world cup",
|
|
||||||
help="Try to be specific and include context for better results"
|
|
||||||
)
|
|
||||||
|
|
||||||
return api_key, query
|
|
||||||
|
|
||||||
async def generate_meme(query: str, api_key: str) -> None:
|
|
||||||
"""
|
|
||||||
Generates a meme using browser automation.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
query (str): User's meme request
|
|
||||||
api_key (str): Anthropic API key
|
|
||||||
"""
|
|
||||||
llm = ChatAnthropic(
|
llm = ChatAnthropic(
|
||||||
model="claude-3-5-sonnet-20240620",
|
model="claude-3-5-sonnet-20240620",
|
||||||
api_key=api_key
|
api_key=api_key
|
||||||
|
|
@ -47,6 +21,7 @@ async def generate_meme(query: str, api_key: str) -> None:
|
||||||
"5. Check the preview making sure it is funny and a meaningful meme. Adjust text directly if needed. \n"
|
"5. Check the preview making sure it is funny and a meaningful meme. Adjust text directly if needed. \n"
|
||||||
"6. Look at the meme and text on it, if it doesnt make sense, PLEASE retry by filling the text boxes with different text. \n"
|
"6. Look at the meme and text on it, if it doesnt make sense, PLEASE retry by filling the text boxes with different text. \n"
|
||||||
"7. Click on the Generate meme button to generate the meme\n"
|
"7. Click on the Generate meme button to generate the meme\n"
|
||||||
|
"8. Copy the image link and give it as the output\n"
|
||||||
).format(query)
|
).format(query)
|
||||||
|
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
|
|
@ -56,26 +31,9 @@ async def generate_meme(query: str, api_key: str) -> None:
|
||||||
max_failures=25
|
max_failures=25
|
||||||
)
|
)
|
||||||
|
|
||||||
with st.spinner("🎨 Generating your meme... Please wait"):
|
history = await agent.run()
|
||||||
await agent.run()
|
history.final_result()
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""
|
|
||||||
Main function to run the Streamlit app.
|
|
||||||
"""
|
|
||||||
st.set_page_config(page_title="AI Meme Generator", page_icon="🎭")
|
|
||||||
|
|
||||||
api_key, query = create_ui()
|
|
||||||
|
|
||||||
if st.button("Generate Meme", disabled=not (api_key and query)):
|
|
||||||
if not api_key:
|
|
||||||
st.error("Please enter your Anthropic API key in the sidebar")
|
|
||||||
return
|
|
||||||
if not query:
|
|
||||||
st.error("Please enter what meme you'd like to generate")
|
|
||||||
return
|
|
||||||
|
|
||||||
asyncio.run(generate_meme(query, api_key))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
query = "Elon Musk bullying sam altman about trump winning the election"
|
||||||
|
asyncio.run(generate_meme(query))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue