File size: 915 Bytes
f3c3d6f
 
a7c3d5e
 
f3c3d6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7c3d5e
 
f3c3d6f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from transformers import AutoModel, AutoTokenizer
import torch
import gradio as gr

# Load the model and tokenizer
model_name = "abdfajar707/rkp_llama3_lora_model"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)

# Define the function for text generation
def generate_text(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model(**inputs)
    logits = outputs.last_hidden_state  # Adjust depending on your model's output
    predicted_indices = torch.argmax(logits, dim=-1)
    predicted_text = tokenizer.decode(predicted_indices[0], skip_special_tokens=True)
    return predicted_text

# Create the Gradio interface
iface = gr.Interface(
    fn=generate_text,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
    outputs="text"
)

# Launch the Gradio interface
iface.launch()