FireStarter2040 commited on
Commit
4de3eaf
·
1 Parent(s): 06aaacb

Fix HF deploy workflow and ignore space clone

Browse files
Files changed (6) hide show
  1. .github/workflows/deploy-hf-space.yml +32 -0
  2. .gitignore +3 -0
  3. Dockerfile +25 -0
  4. README.md +13 -0
  5. app.py +41 -7
  6. requirements.txt +1 -0
.github/workflows/deploy-hf-space.yml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy to Hugging Face Space
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ deploy:
9
+ runs-on: ubuntu-latest
10
+
11
+ env:
12
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
13
+ HF_SPACE_ID: FireStarter2040/firestarter-chat
14
+
15
+ steps:
16
+ - name: Checkout repo
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Setup Git identity
20
+ run: |
21
+ git config --global user.name "FireStarter CI"
22
+ git config --global user.email "ci@firestarter.local"
23
+
24
+ - name: Set HuggingFace remote
25
+ run: |
26
+ git remote remove hf || true
27
+ git remote add hf https://huggingface.co/spaces/$HF_SPACE_ID
28
+ git remote set-url hf https://FireStarter2040:$HF_TOKEN@huggingface.co/spaces/$HF_SPACE_ID
29
+
30
+ - name: Force push to HF Space
31
+ run: |
32
+ git push hf main --force
.gitignore CHANGED
@@ -15,3 +15,6 @@ venv/
15
 
16
  # Locks
17
  requirements.lock
 
 
 
 
15
 
16
  # Locks
17
  requirements.lock
18
+
19
+ # Hugging Face Space clone (optional)
20
+ firestarter-chat/
Dockerfile ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Dependências básicas do sistema
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ build-essential \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ # Copia requirements
11
+ COPY requirements.txt .
12
+
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # Copia código
16
+ COPY . .
17
+
18
+ # Porta padrão do Gradio / HF
19
+ EXPOSE 7860
20
+
21
+ # Variáveis default (pode sobrescrever em runtime)
22
+ ENV FS_MODE=gradio
23
+
24
+ # Entrada
25
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Chat App — FireStarter Edition
2
 
3
  Aplicação minimalista para interação com modelos OpenAI/HuggingFace usando Python, dotenv e uma interface simples.
 
1
+ ---
2
+ title: FireStarter Chat
3
+ emoji: "🔥"
4
+ colorFrom: red
5
+ colorTo: black
6
+ sdk: gradio
7
+ sdk_version: 5.44.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: FireStarter minimal chat over OpenAI API
12
+ ---
13
+
14
  # Chat App — FireStarter Edition
15
 
16
  Aplicação minimalista para interação com modelos OpenAI/HuggingFace usando Python, dotenv e uma interface simples.
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from dotenv import load_dotenv
3
  from openai import OpenAI
 
4
 
5
  load_dotenv()
6
 
@@ -13,20 +14,53 @@ if not OPENAI_API_KEY:
13
  client = OpenAI(api_key=OPENAI_API_KEY)
14
 
15
 
16
- def chat(prompt: str):
17
- """Função principal de interação com o modelo."""
18
  resp = client.chat.completions.create(
19
  model=MODEL_NAME,
20
  messages=[{"role": "user", "content": prompt}],
21
  )
22
- return resp.choices[0].message["content"]
 
23
 
24
 
25
- if __name__ == "__main__":
26
- print("🔥 FireStarter Chat pronto")
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  while True:
28
- msg = input("\nVocê: ").strip()
 
 
 
 
 
29
  if msg.lower() in ("exit", "quit"):
30
  break
31
- print("\nAI:", chat(msg))
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  from dotenv import load_dotenv
3
  from openai import OpenAI
4
+ import gradio as gr
5
 
6
  load_dotenv()
7
 
 
14
  client = OpenAI(api_key=OPENAI_API_KEY)
15
 
16
 
17
+ def chat(prompt: str) -> str:
18
+ """Backend principal de interação com o modelo."""
19
  resp = client.chat.completions.create(
20
  model=MODEL_NAME,
21
  messages=[{"role": "user", "content": prompt}],
22
  )
23
+ msg = resp.choices[0].message
24
+ return getattr(msg, "content", msg.get("content"))
25
 
26
 
27
+ def gradio_chat_fn(message, history):
28
+ """Wrapper para ChatInterface: ignora history e usa backend único."""
29
+ return chat(message)
30
+
31
+
32
+ def build_ui() -> gr.Blocks:
33
+ return gr.ChatInterface(
34
+ fn=gradio_chat_fn,
35
+ title="🔥 FireStarter Chat",
36
+ description="Minimal OpenAI chat powered by FireStarter.",
37
+ )
38
+
39
+
40
+ def run_cli():
41
+ print("🔥 FireStarter Chat — modo CLI (digite 'exit' para sair)")
42
  while True:
43
+ try:
44
+ msg = input("\nVocê: ").strip()
45
+ except (EOFError, KeyboardInterrupt):
46
+ print("\nSaindo.")
47
+ break
48
+
49
  if msg.lower() in ("exit", "quit"):
50
  break
 
51
 
52
+ try:
53
+ resp = chat(msg)
54
+ print("\nAI:", resp)
55
+ except Exception as e:
56
+ print(f"\n[ERRO] {e}")
57
+
58
+
59
+ if __name__ == "__main__":
60
+ mode = os.getenv("FS_MODE", "gradio").lower()
61
+
62
+ if mode == "cli":
63
+ run_cli()
64
+ else:
65
+ demo = build_ui()
66
+ demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  huggingface_hub==0.25.2
2
  openai
3
  python-dotenv
 
 
1
  huggingface_hub==0.25.2
2
  openai
3
  python-dotenv
4
+ gradio==5.44.0