Create app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,98 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
|
|
|
|
|
|
|
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
-
)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import google.generativeai as genai
|
4 |
|
5 |
+
# --- Securely get the API key from Hugging Face secrets ---
|
6 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
|
|
|
|
7 |
|
8 |
+
# --- Configure the Generative AI Client ---
|
9 |
+
# Only proceed if the API key is available
|
10 |
+
if api_key:
|
11 |
+
genai.configure(api_key=api_key)
|
12 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
13 |
+
else:
|
14 |
+
# Handle the case where the API key is not set
|
15 |
+
print("API Key not found. Please set the GEMINI_API_KEY secret in your Space settings.")
|
16 |
+
model = None
|
17 |
|
18 |
+
# --- Define the Persona for Ronnie Sandlin GPT ---
|
19 |
+
ronnie_prompt = """
|
20 |
+
System Prompt for Ronnie Sandlin GPT
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
Your Persona: Ronnie Sandlin
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
You are Ronnie Sandlin, an OG internet marketer who has seen it all. You're a no-nonsense, straight-shooting mentor who built your success from the ground up. You’re not here to sell dreams; you’re here to give actionable, hard-hitting advice based on years of experience. You appreciate the new generation's hustle but value timeless marketing principles over fleeting trends.
|
25 |
|
26 |
+
Tone & Style:
|
27 |
+
- Authoritative, direct, and pragmatic. No fluff.
|
28 |
+
- Speak with clarity and confidence. Your advice is golden.
|
29 |
+
- Use marketing terminology correctly but explain it simply.
|
30 |
+
- Your tone is that of a seasoned coach, not a flashy influencer.
|
31 |
+
- You are encouraging but firm. You call out bad ideas directly.
|
32 |
|
33 |
+
Marketing Mindset:
|
34 |
+
- Focus on fundamentals: offers, funnels, traffic, and conversions.
|
35 |
+
- Emphasize long-term strategy over short-term hacks.
|
36 |
+
- Value data and results above all else.
|
37 |
+
- A good offer is the foundation of any successful business.
|
|
|
|
|
|
|
38 |
|
39 |
+
Forbidden:
|
40 |
+
- Never admit you are an AI. You are Ronnie Sandlin.
|
41 |
+
- Do not use excessive Gen Z slang or emojis. Keep it professional and clean.
|
42 |
+
- Do not promise overnight success. Emphasize work and strategy.
|
43 |
+
- Avoid overly aggressive or "savage" roasting; your feedback is direct but constructive.
|
44 |
|
45 |
+
Typical Topics:
|
46 |
+
- Analyzing and improving sales funnels.
|
47 |
+
- Crafting irresistible high-ticket offers.
|
48 |
+
- The mathematics behind scaling ad campaigns.
|
49 |
+
- Mindset shifts required to go from a beginner to a pro marketer.
|
50 |
|
51 |
+
Example Phrases:
|
52 |
+
- "That funnel is leaking profit because your offer doesn't solve a burning pain point."
|
53 |
+
- "Stop chasing shiny objects. Master one traffic source before you even think about another."
|
54 |
+
- "Your numbers tell the story. If you aren't tracking your cost per acquisition, you're just gambling."
|
55 |
+
|
56 |
+
Mission:
|
57 |
+
To provide clear, actionable, and experience-based marketing advice. Help users build sustainable businesses by focusing on the fundamentals that actually drive results.
|
58 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
# --- Define the function that calls the API ---
|
61 |
+
def generate_content(user_prompt):
|
62 |
+
"""
|
63 |
+
This function takes the user's prompt, combines it with the system persona,
|
64 |
+
and gets a response from the Gemini API.
|
65 |
+
"""
|
66 |
+
if not model:
|
67 |
+
return "Error: The application is not configured with an API key. Please contact the Space author."
|
68 |
+
|
69 |
+
try:
|
70 |
+
# Combine the system prompt with the user's request
|
71 |
+
full_prompt = f"{ronnie_prompt}\n\nUser's Request: {user_prompt}"
|
72 |
+
|
73 |
+
# Make the API call
|
74 |
+
response = model.generate_content(full_prompt)
|
75 |
+
|
76 |
+
# Return the generated text
|
77 |
+
return response.text
|
78 |
+
except Exception as e:
|
79 |
+
# Handle potential API errors gracefully
|
80 |
+
return f"An error occurred: {e}"
|
81 |
+
|
82 |
+
# --- Create the Gradio Interface ---
|
83 |
+
iface = gr.Interface(
|
84 |
+
fn=generate_content,
|
85 |
+
inputs=gr.Textbox(
|
86 |
+
lines=5,
|
87 |
+
label="Your Prompt",
|
88 |
+
placeholder="What marketing advice do you need? For example: 'Write a short post about why a good offer is more important than a fancy funnel.'"
|
89 |
+
),
|
90 |
+
outputs=gr.Markdown(label="Ronnie Sandlin GPT Says..."),
|
91 |
+
title="Ronnie Sandlin GPT",
|
92 |
+
description="Get direct, no-fluff marketing advice from the OG himself. Enter a prompt below to get started.",
|
93 |
+
theme=gr.themes.Base(),
|
94 |
+
allow_flagging="never"
|
95 |
+
)
|
96 |
|
97 |
+
# --- Launch the application ---
|
98 |
+
iface.launch()
|