File size: 2,768 Bytes
c80ca44
540e4af
 
bd8f847
c80ca44
 
5e19355
a5dff1e
c80ca44
 
 
 
5e19355
c80ca44
 
 
 
540e4af
c80ca44
 
 
540e4af
 
5e19355
540e4af
 
 
 
 
c80ca44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e19355
540e4af
 
c80ca44
 
540e4af
5e19355
540e4af
 
c80ca44
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# app.py
import os
import requests
import gradio as gr

# === CONFIG ===
HF_TOKEN = os.environ.get("HF_TOKEN")
MODEL = "Qwen/Qwen3-Next-80B-A3B-Thinking:together"  # ✅ DZIAŁAJĄCY POLSKI MODEL

headers = {"Authorization": f"Bearer {HF_TOKEN}"}

def call_model(prompt):
    url = f"https://api-inference.huggingface.co/models/{MODEL}"  # ✅ BEZ SPACJI!
    payload = {
        "inputs": prompt,
        "parameters": {
            "max_new_tokens": 400,
            "temperature": 0.9,
            "top_p": 0.95
        }
    }
    try:
        r = requests.post(url, headers=headers, json=payload, timeout=60)
        r.raise_for_status()
        data = r.json()
    except requests.exceptions.RequestException as e:
        return f"⚠️ Błąd połączenia: {str(e)}"
    except Exception as e:
        return f"⚠️ Nieoczekiwany błąd: {str(e)}"

    if isinstance(data, dict) and data.get("error"):
        return "⚠️ Błąd modelu: " + data.get("error")
    if isinstance(data, list) and data and isinstance(data[0], dict):
        return data[0].get("generated_text", str(data))
    if isinstance(data, dict):
        return data.get("generated_text", str(data))
    return str(data)

def generate_posts(temat, ton, platforma):
    prompt = f"""
Jesteś ekspertem od pisania angażujących postów na social media w języku polskim.
Temat: {temat}
Platforma: {platforma}
Ton: {ton}
Twoje zadanie:
Wygeneruj 3 różne warianty posta. Każdy wariant podaj w tym formacie:
---
Wariant X:
1) Hook: (1 krótkie, chwytliwe zdanie)
2) Treść: (dostosowana do platformy – 
   • TikTok/Instagram: max 3 zdania, dynamiczne, z emoji
   • Facebook: 3–5 zdań, angażujące, lekkie
   • LinkedIn: 6–8 zdań, profesjonalne, z wartością merytoryczną)
3) Hashtagi: (10 propozycji, oddzielone przecinkami, bez polskich znaków)
4) CTA: (1 krótka linia zachęcająca do działania)
5) Sugestia wizualna: (jedno zdanie, opis pomysłu na zdjęcie/wideo)
---
Pisz konkretnie, naturalnym językiem, bez powtarzania instrukcji.
"""
    out = call_model(prompt)
    return out

iface = gr.Interface(
    fn=generate_posts,
    inputs=[
        gr.Textbox(label="🎯 Temat", placeholder="Wpisz temat..."),
        gr.Dropdown(["motywacyjny", "informacyjny", "sprzedażowy", "edukacyjny"], label="🎙 Ton", value="motywacyjny"),
        gr.Dropdown(["TikTok", "Instagram", "Facebook", "LinkedIn"], label="📱 Platforma", value="LinkedIn")
    ],
    outputs=gr.Textbox(label="✨ Wygenerowane posty", lines=25),
    title="🤖 Generator Postów AI — po polsku",
    description="Podaj temat, wybierz ton i platformę. Agent wygeneruje 3 gotowe propozycje.",
    theme="soft",
    allow_flagging="never"
)

if __name__ == "__main__":
    iface.launch()