Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# Load the large language model (LLM) | |
try: | |
# Load model directly | |
from transformers import AutoProcessor, AutoModelForPreTraining | |
processor = AutoProcessor.from_pretrained("meta-llama/Llama-3.2-11B-Vision-Instruct") | |
model = AutoModelForPreTraining.from_pretrained("meta-llama/Llama-3.2-11B-Vision-Instruct") # You can use a different model here | |
print("Model loaded successfully!") | |
except Exception as e: | |
print(f"Error loading model: {e}") | |
llm_pipeline = None | |
# Define the function to generate text based on input prompt | |
def generate_text(prompt): | |
if llm_pipeline is None: | |
return "Error: Model not loaded." | |
result = llm_pipeline(prompt, max_length=100, num_return_sequences=1) | |
return result[0]['generated_text'] | |
# Create the Gradio interface | |
interface = gr.Interface( | |
fn=generate_text, | |
inputs=gr.Textbox(lines=7, label="Input Prompt"), | |
outputs="text", | |
title="Large Language Model Text Generation", | |
description="Enter a prompt to generate text using a large language model." | |
) | |
print("Launching the Gradio interface...") | |
# Launch the interface | |
interface.launch() | |