mayone-secuirty / inference.py
theghostcmd's picture
Create inference.py
91a6006 verified
Raw
History Blame Contribute Delete
1.09 kB
import os
import gradio as gr
from openai import OpenAI # if you use LLM calls
# Environment variables – NO DEFAULTS for HF_TOKEN
API_BASE_URL = os.getenv("API_BASE_URL") # default not allowed? The instruction says defaults are set only for API_BASE_URL and MODEL_NAME (not HF_TOKEN). So you can set a default for API_BASE_URL and MODEL_NAME, but HF_TOKEN must remain None if missing.
MODEL_NAME = os.getenv("MODEL_NAME")
HF_TOKEN = os.getenv("HF_TOKEN") # must NOT have a default value
# Optional – only if you use from_docker_image()
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
# Your inference logic (example)
def predict(packet_data):
# Use API_BASE_URL, MODEL_NAME, HF_TOKEN if needed
# For now, return a dummy result
return {"anomaly_score": 0.92, "verdict": "malicious"}
# Gradio interface (or whatever the assignment expects)
iface = gr.Interface(
fn=predict,
inputs=gr.Textbox(label="Packet data"),
outputs=gr.JSON(label="Detection result")
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)