YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
YAML transformers
import os import gradio as gr from huggingface_hub import InferenceClient
1. Initialize the Inference Client
Replace 'your_hf_token_here' with the token copied from Step 1
HF_TOKEN = "your_hf_token_here" client = InferenceClient(model="meta-llama/Llama-3-8B-Instruct", token=HF_TOKEN)
2. Define the core prediction logic
def generate_response(prompt): try: # Call the Inference API response = client.text_generation(prompt, max_new_tokens=150) return response except Exception as e: return f"Error connecting to Hugging Face API: {str(e)}"
3. Create the Web Interface (Gradio)
demo = gr.Interface( fn=generate_response, inputs=gr.Textbox(lines=2, placeholder="Ask the model anything..."), outputs="text", title="Hugging Face Model Interface", description="Ask questions via the Hugging Face serverless Inference API." )
4. Launch the application
if name == "main": demo.launch(share=True)