Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
# Carga
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Define una funci贸n para procesar las solicitudes
|
| 8 |
def process_prompt(prompt):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Configura la interfaz de API con Gradio
|
| 13 |
interface = gr.Interface(
|
| 14 |
fn=process_prompt,
|
| 15 |
inputs="text",
|
| 16 |
outputs="text",
|
| 17 |
-
title="Hugging Face Space API",
|
| 18 |
-
description="Modelo ligero basado en
|
| 19 |
)
|
| 20 |
|
| 21 |
# Ejecuta la app
|
| 22 |
if __name__ == "__main__":
|
| 23 |
interface.launch(share=True)
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
|
| 4 |
+
# Carga el modelo Phi-4 desde Hugging Face
|
| 5 |
+
llm = Llama.from_pretrained(
|
| 6 |
+
repo_id="unsloth/phi-4-GGUF",
|
| 7 |
+
filename="phi-4-F16.gguf",
|
| 8 |
+
)
|
| 9 |
|
| 10 |
# Define una funci贸n para procesar las solicitudes
|
| 11 |
def process_prompt(prompt):
|
| 12 |
+
"""
|
| 13 |
+
Procesa el prompt usando el modelo Phi-4.
|
| 14 |
+
"""
|
| 15 |
+
try:
|
| 16 |
+
# Genera una respuesta usando el modelo Phi-4
|
| 17 |
+
response = llm.create_chat_completion(
|
| 18 |
+
messages=[
|
| 19 |
+
{
|
| 20 |
+
"role": "user",
|
| 21 |
+
"content": prompt
|
| 22 |
+
}
|
| 23 |
+
]
|
| 24 |
+
)
|
| 25 |
+
# Extrae y devuelve el texto generado
|
| 26 |
+
return response["choices"][0]["message"]["content"]
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return f"Error al procesar el prompt: {e}"
|
| 29 |
|
| 30 |
# Configura la interfaz de API con Gradio
|
| 31 |
interface = gr.Interface(
|
| 32 |
fn=process_prompt,
|
| 33 |
inputs="text",
|
| 34 |
outputs="text",
|
| 35 |
+
title="Hugging Face Space API - Phi-4",
|
| 36 |
+
description="Modelo ligero basado en Phi-4 para probar vulnerabilidades con RedTeamer.",
|
| 37 |
)
|
| 38 |
|
| 39 |
# Ejecuta la app
|
| 40 |
if __name__ == "__main__":
|
| 41 |
interface.launch(share=True)
|
| 42 |
+
|