Spaces:
Runtime error
Runtime error
import gradio as gr | |
import transformers | |
import torch | |
# 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}, | |
device_map="auto", | |
) | |
# Define the function to generate text | |
def generate_text(input_text, max_new_tokens=128, temperature=1.0, top_k=50, top_p=0.95): | |
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.inputs.Textbox(lines=2, placeholder="Enter your text here...", label="Input Text"), | |
gr.inputs.Slider(minimum=1, maximum=200, default=128, step=1, label="Max New Tokens"), | |
gr.inputs.Slider(minimum=0.1, maximum=2.0, default=1.0, step=0.1, label="Temperature"), | |
gr.inputs.Slider(minimum=1, maximum=100, default=50, step=1, label="Top-k"), | |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=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() | |