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