Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,28 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
# Récupération du
|
| 6 |
token = os.getenv("SecretToken")
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
client = InferenceClient(
|
| 10 |
-
"ShadowEternity/CTFsolver",
|
| 11 |
-
token=token,
|
| 12 |
-
timeout=120
|
| 13 |
-
)
|
| 14 |
|
| 15 |
-
def
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
max_new_tokens=512,
|
| 21 |
-
stream=False
|
| 22 |
-
)
|
| 23 |
-
return response
|
| 24 |
except Exception as e:
|
| 25 |
-
|
| 26 |
|
| 27 |
-
#
|
| 28 |
demo = gr.ChatInterface(
|
| 29 |
-
fn=
|
| 30 |
-
title="CTF Solver
|
| 31 |
-
description="Assistant
|
| 32 |
)
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
-
demo.launch()
|
|
|
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
# Récupération du SecretToken (Assurez-vous qu'il est correct dans Settings)
|
| 6 |
token = os.getenv("SecretToken")
|
| 7 |
|
| 8 |
+
# Utilisation du client API pour CTFsolver
|
| 9 |
+
client = InferenceClient("ShadowEternity/CTFsolver", token=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
def chat_fn(message, history):
|
| 12 |
+
# Utilisation du streaming pour une meilleure stabilité de l'API
|
| 13 |
+
partial_message = ""
|
| 14 |
try:
|
| 15 |
+
for token_out in client.text_generation(message, max_new_tokens=512, stream=True):
|
| 16 |
+
partial_message += token_out
|
| 17 |
+
yield partial_message
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
+
yield f"Problème d'API : {str(e)}. Vérifiez votre SecretToken ou attendez 1 minute."
|
| 20 |
|
| 21 |
+
# Interface de Chat professionnelle
|
| 22 |
demo = gr.ChatInterface(
|
| 23 |
+
fn=chat_fn,
|
| 24 |
+
title="CTF Solver - API Mode",
|
| 25 |
+
description="Assistant technique pour la cybersécurité."
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|