Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load your fine-tuned model
|
5 |
+
model_name = "ayeshaNoor1/Llama_finetunedModel-1b"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define the text generation function
|
10 |
+
def generate_text(prompt):
|
11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
12 |
+
outputs = model.generate(inputs.input_ids, max_length=100, num_return_sequences=1)
|
13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return response
|
15 |
+
|
16 |
+
# Create a Gradio interface
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=generate_text,
|
19 |
+
inputs="text",
|
20 |
+
outputs="text",
|
21 |
+
title="Fine-Tuned Llama 3.2 Generator",
|
22 |
+
description="Enter a prompt to generate text using the fine-tuned Llama model.",
|
23 |
+
)
|
24 |
+
|
25 |
+
# Launch the Gradio app
|
26 |
+
if __name__ == "__main__":
|
27 |
+
interface.launch()
|