File size: 1,037 Bytes
7696cf8
47ab986
 
 
cdc1fda
26792fc
 
2602485
 
 
cdc1fda
 
1098c9d
47ab986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from transformers import pipeline

# Get the Hugging Face API token from environment variables
api_token = os.getenv("HUGGINGFACE_API_TOKEN_V")
print('----------------',api_token,'-----------------')
# Check if the API token is set
if not api_token:
    raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")

# Initialize the text generation pipeline with authentication
pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3.1-405B", use_auth_token=True)

# Define the function to generate text
def generate_text(prompt):
    result = pipe(prompt, max_length=50, num_return_sequences=1)
    return result[0]['generated_text']

# Create a Gradio interface
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."
)

# Launch the interface
iface.launch()