ting-classifier / app.py
ziggylott's picture
Upload app.py with huggingface_hub
578c9ad verified
Raw
History Blame Contribute Delete
1.8 kB
import gradio as gr
import os
from groq import Groq
# Initialize Groq
api_key = os.getenv("GROQ_API_KEY", "")
if not api_key:
gr.Warning("GROQ_API_KEY not set!")
client = Groq(api_key=api_key)
def classify_support(msg):
"""Classify Whop support messages"""
try:
resp = client.messages.create(
model="llama-3.3-70b-versatile",
max_tokens=200,
system="Classify this Whop customer message as: Billing, Technical, Feature Request, Positive, or Negative. Respond in JSON.",
messages=[{"role": "user", "content": msg}]
)
return resp.content[0].text
except Exception as e:
return f"Error: {str(e)}"
def tag_post(post):
"""Tag social media posts"""
try:
resp = client.messages.create(
model="llama-3.3-70b-versatile",
max_tokens=200,
system="Tag this social post as: Educational, Motivational, Product, Behind-the-scenes, or Community. Respond in JSON.",
messages=[{"role": "user", "content": post}]
)
return resp.content[0].text
except Exception as e:
return f"Error: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("# 🎯 Ting's Content Classifier")
with gr.Tabs():
with gr.TabItem("🛍️ Support Classifier"):
inp = gr.Textbox(label="Message", lines=3)
btn = gr.Button("Classify")
out = gr.Textbox(label="Result", lines=3)
btn.click(classify_support, inp, out)
with gr.TabItem("📱 Post Tagger"):
inp2 = gr.Textbox(label="Post", lines=4)
btn2 = gr.Button("Tag")
out2 = gr.Textbox(label="Tags", lines=3)
btn2.click(tag_post, inp2, out2)
if __name__ == "__main__":
demo.launch()