Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
|
|
|
2 |
from transformers import AutoModel, AutoTokenizer
|
3 |
|
4 |
# Load the model and tokenizer
|
@@ -6,13 +7,26 @@ model_name = "Rafay17/Llama3.2_1b_customModle2"
|
|
6 |
model = AutoModel.from_pretrained(model_name)
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
-
#
|
10 |
-
input_text
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
|
5 |
# Load the model and tokenizer
|
|
|
7 |
model = AutoModel.from_pretrained(model_name)
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
+
# Define a function to process input text
|
11 |
+
def generate_output(input_text):
|
12 |
+
# Tokenize the input text
|
13 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
14 |
+
|
15 |
+
# Forward pass to get model outputs
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model(**inputs)
|
18 |
+
|
19 |
+
# You can return the outputs as needed; here, we're returning the last hidden state
|
20 |
+
return outputs.last_hidden_state
|
21 |
|
22 |
+
# Create Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=generate_output,
|
25 |
+
inputs=gr.Textbox(label="Input Text"),
|
26 |
+
outputs=gr.Textbox(label="Model Output"),
|
27 |
+
title="Text Processing with Llama Model",
|
28 |
+
description="Enter text to process it with the Llama3.2 model."
|
29 |
+
)
|
30 |
|
31 |
+
# Launch the app
|
32 |
+
iface.launch()
|