|
import os |
|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
api_token = os.getenv("HUGGINGFACE_API_TOKEN") |
|
|
|
|
|
if not api_token: |
|
raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.") |
|
|
|
|
|
pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3.1-405B", use_auth_token=api_token) |
|
|
|
|
|
def generate_text(prompt): |
|
result = pipe(prompt, max_length=50, num_return_sequences=1) |
|
return result[0]['generated_text'] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_text, |
|
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."), |
|
outputs="text", |
|
title="Meta-Llama Text Generation", |
|
description="Generate text using the Meta-Llama 3.1 405B model." |
|
) |
|
|
|
|
|
iface.launch() |