File size: 902 Bytes
4f525f2
dc8c02d
a809454
 
 
 
 
 
 
4f525f2
dc8c02d
4f525f2
 
 
 
 
 
 
 
 
dc8c02d
 
4f525f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from hf_olmo import AutoModelForCausalLM, AutoTokenizer  # Importando do hf_olmo
import os

# Configurar PKG_CONFIG_PATH
os.environ['PKG_CONFIG_PATH'] = '/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'

# Resto do código do app
from transformers import AutoTokenizer, AutoModelForCausalLM

# Carregar o modelo e tokenizer
model_name = "allenai/OLMo-7B"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)

def generate_text(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

iface = gr.Interface(fn=generate_text, inputs="text", outputs="text",
                     title="OLMo-7B Text Generator", description="Enter a prompt to generate text.")
iface.launch()