Spaces:
Sleeping
Sleeping
File size: 1,082 Bytes
b91d08d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import os
import gradio as gr
from huggingface_hub import InferenceClient
# Load HF token securely from environment
HF_TOKEN = os.getenv("HF_TOKEN")
# Model you want to use (hosted on Hugging Face)
MODEL_NAME = "mistralai/Voxtral-Small-24B-2507"
# Create the inference client
client = InferenceClient(model=MODEL_NAME, token=HF_TOKEN)
# Function to generate text
def chat_with_model(prompt):
if not prompt.strip():
return "Please enter a message."
try:
response = client.text_generation(
prompt,
max_new_tokens=200,
temperature=0.7,
)
return response
except Exception as e:
return f"⚠️ Error: {str(e)}"
# Gradio UI
interface = gr.Interface(
fn=chat_with_model,
inputs=gr.Textbox(label="Your Message", placeholder="Type your question here..."),
outputs=gr.Textbox(label="Model Response"),
title="Voxtral-Small-24B-2507 Chatbot",
description="Chat live with the Mistral Voxtral Small 24B model via Hugging Face Inference API.",
)
# Launch the app
interface.launch()
|