igea-pretrained / app.py
Detsutut's picture
Update app.py
5ed1df0 verified
raw
history blame
1.38 kB
import gradio as gr
import transformers
import torch
import os
hf_key = os.getenv("HF_TOKEN")
# Initialize the model
model_id = "bmi-labmedinfo/Igea-350M-v0.0.1"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
token=hf_key
)
# Define the function to generate text
def generate_text(input_text, max_new_tokens, temperature, top_k, top_p):
output = pipeline(
input_text,
max_new_tokens=max_new_tokens,
temperature=temperature,
top_k=top_k,
top_p=top_p,
)
return output[0]['generated_text']
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.Textbox(lines=2, placeholder="Enter your text here...", label="Input Text"),
gr.Slider(minimum=1, maximum=200, value=128, step=1, label="Max New Tokens"),
gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature"),
gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Top-k"),
gr.Slider(minimum=0.0, maximum=1.0, value=0.95, step=0.01, label="Top-p")
],
outputs="text",
title="Text Generation Interface",
description="Enter a prompt to generate text using the Igea-350M model and adjust the hyperparameters."
)
# Launch the interface
if __name__ == "__main__":
iface.launch()