Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import os, requests
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") # ustaw w Secrets Space
|
| 6 |
+
MODEL = "google/flan-t5-base" # lekki model instrukcyjny (mo偶esz zmieni膰)
|
| 7 |
+
|
| 8 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 9 |
+
|
| 10 |
+
def call_model(prompt):
|
| 11 |
+
url = f"https://api-inference.huggingface.co/models/{MODEL}"
|
| 12 |
+
payload = {"inputs": prompt, "parameters": {"max_new_tokens": 200}}
|
| 13 |
+
r = requests.post(url, headers=headers, json=payload, timeout=60)
|
| 14 |
+
data = r.json()
|
| 15 |
+
# obs艂uga r贸偶nych format贸w odpowiedzi
|
| 16 |
+
if isinstance(data, dict) and data.get("error"):
|
| 17 |
+
return "B艂膮d modelu: " + data.get("error")
|
| 18 |
+
if isinstance(data, list) and data and isinstance(data[0], dict):
|
| 19 |
+
return data[0].get("generated_text", str(data))
|
| 20 |
+
if isinstance(data, dict):
|
| 21 |
+
return data.get("generated_text", str(data))
|
| 22 |
+
return str(data)
|
| 23 |
+
|
| 24 |
+
def generate_posts(temat, ton, platforma):
|
| 25 |
+
prompt = f"""Jeste艣 ekspertem od pisania anga偶uj膮cych post贸w na social media.
|
| 26 |
+
Temat: {temat}
|
| 27 |
+
Platforma: {platforma}
|
| 28 |
+
Ton: {ton}
|
| 29 |
+
|
| 30 |
+
Wygeneruj 3 warianty. Ka偶dy wariant podaj w formacie:
|
| 31 |
+
1) Hook:
|
| 32 |
+
2) Tre艣膰:
|
| 33 |
+
3) Hashtagi:
|
| 34 |
+
4) CTA:
|
| 35 |
+
5) Sugestia wizualna:
|
| 36 |
+
U偶yj j臋zyka polskiego."""
|
| 37 |
+
out = call_model(prompt)
|
| 38 |
+
return out
|
| 39 |
+
|
| 40 |
+
iface = gr.Interface(
|
| 41 |
+
fn=generate_posts,
|
| 42 |
+
inputs=[
|
| 43 |
+
gr.Textbox(label="Temat (np. Jak wsta膰 o 5 rano)"),
|
| 44 |
+
gr.Dropdown(["motywacyjny","informacyjny","sprzeda偶owy","edukacyjny"], label="Ton"),
|
| 45 |
+
gr.Dropdown(["TikTok","Instagram","LinkedIn","Facebook"], label="Platforma")
|
| 46 |
+
],
|
| 47 |
+
outputs=gr.Textbox(label="Wynik"),
|
| 48 |
+
title="Social Media Post Generator (MVP)"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
iface.launch()
|