Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,28 +14,23 @@ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")
|
|
14 |
# Load the processor
|
15 |
processor = AutoProcessor.from_pretrained(model_id)
|
16 |
|
17 |
-
# Define an image URL
|
18 |
-
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
# Decode and print the output
|
41 |
-
print(processor.decode(output[0][inputs["input_ids"].shape[-1]:]))
|
|
|
14 |
# Load the processor
|
15 |
processor = AutoProcessor.from_pretrained(model_id)
|
16 |
|
|
|
|
|
17 |
|
18 |
+
# Define the function to generate text based on input prompt
|
19 |
+
def generate_text(prompt):
|
20 |
+
if llm_pipeline is None:
|
21 |
+
return "Error: Model not loaded."
|
22 |
+
result = llm_pipeline(prompt, max_length=100, num_return_sequences=1)
|
23 |
+
return result[0]['generated_text']
|
24 |
+
|
25 |
+
# Create the Gradio interface
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=generate_text,
|
28 |
+
inputs=gr.Textbox(lines=7, label="Input Prompt"),
|
29 |
+
outputs="text",
|
30 |
+
title="Large Language Model Text Generation",
|
31 |
+
description="Enter a prompt to generate text using a large language model."
|
32 |
+
)
|
33 |
+
|
34 |
+
print("Launching the Gradio interface...")
|
35 |
+
# Launch the interface
|
36 |
+
interface.launch()
|
|
|
|
|
|