Rafay17 commited on
Commit
240e8bf
·
verified ·
1 Parent(s): e8ec2f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -1,4 +1,5 @@
1
- # Import necessary libraries
 
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
- # Prepare your input text
10
- input_text = "Your input text goes here."
11
- inputs = tokenizer(input_text, return_tensors="pt")
 
 
 
 
 
 
 
 
12
 
13
- # Forward pass to get model outputs
14
- with torch.no_grad():
15
- outputs = model(**inputs)
 
 
 
 
 
16
 
17
- # Do something with the outputs
18
- print(outputs)
 
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()