abdibrokhim commited on
Commit
774d59e
·
1 Parent(s): a3f0c82

try notl.ink the best url shortener built with rust pl

Browse files
Files changed (2) hide show
  1. .gitignore +5 -0
  2. app.py +68 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .env
2
+ .venv
3
+ prompts.md
4
+ .aixplain_cache
5
+ .gradio
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from aixplain.factories import AgentFactory, ModelFactory
4
+
5
+ # Function to generate keywords
6
+ def generate_keywords(api_key, topic):
7
+ # Set aiXplain API key dynamically
8
+ os.environ["TEAM_API_KEY"] = api_key
9
+
10
+ # Create the AI agent for keyword generation
11
+ agent = AgentFactory.create(
12
+ api_key=api_key,
13
+ name="SEO Keyword Generator",
14
+ description="Generate a list of SEO keywords based on the provided topic.",
15
+ llm_id="6646261c6eb563165658bbb1" # GPT-4o as per aiXplain documentation
16
+ )
17
+
18
+ # Validate topic length
19
+ words = topic.split()
20
+ if len(words) > 250:
21
+ return "Error: Topic exceeds 150 words. Please shorten it and try again."
22
+
23
+ try:
24
+ # Run the agent with the topic
25
+ response = agent.run(topic)
26
+ keywords_str = response['data']['output'] # Extract output from agent response
27
+
28
+ # Format keywords as a bullet list (assuming comma-separated string)
29
+ keywords = keywords_str.split(',')
30
+ formatted_keywords = "\n".join([f"- {kw.strip()}" for kw in keywords])
31
+ return formatted_keywords
32
+ except Exception as e:
33
+ return f"Error: Failed to generate keywords. Details: {str(e)}"
34
+
35
+ # Create the Gradio interface
36
+ demo = gr.Interface(
37
+ fn=generate_keywords,
38
+ inputs=[
39
+ gr.Textbox(
40
+ lines=1,
41
+ placeholder="Enter your API Key here",
42
+ label="API Key",
43
+ type="password" # Hide API key input for security
44
+ ),
45
+ gr.Textbox(
46
+ lines=5,
47
+ placeholder="Enter your topic here (max 150 words)",
48
+ label="Your Topic"
49
+ )
50
+ ],
51
+ outputs=gr.Textbox(
52
+ label="Generated SEO Keywords",
53
+ lines=10
54
+ ),
55
+ title="SEO Keyword Generator",
56
+ description="Type a topic (up to 200 words) and get SEO keyword suggestions instantly! Perfect for content creators and marketers. Built with [aiXplain](https://aixplain.com?utm_source=abdibrokhim) by [abdibrokhim](https://yaps.gg)",
57
+ examples=[
58
+ ["Latest trends in artificial intelligence"],
59
+ ["Best practices for remote work"],
60
+ ["How to improve website SEO"],
61
+ ["Healthy recipes for busy professionals"]
62
+ ],
63
+ theme="soft", # A cool, user-friendly theme
64
+ flagging_mode="never" # Optional: Disable flagging for inappropriate content
65
+ )
66
+
67
+ # Launch the app
68
+ demo.launch()