File size: 886 Bytes
b5e93ad
 
a9d61a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
import gradio as gr

gr.load("models/mistralai/Mistral-Nemo-Instruct-2407").launch()

import gradio as gr
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer

# Load pre-trained BlackMamba model and tokenizer
model_name = "blackmamba"
model = GPT2LMHeadModel.from_pretrained(model_name)
tokenizer = GPT2Tokenizer.from_pretrained(model_name)

def generate_text(prompt, max_length=50):
    inputs = tokenizer.encode(prompt, return_tensors="pt")
    outputs = model.generate(inputs, max_length=max_length, num_return_sequences=1)
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return generated_text

# Create Gradio interface
iface = gr.Interface(
    fn=generate_text,
    inputs="text",
    outputs="text",
    title="WormGPT",
    description="An evil brother of ChatGPT for Hugging Face Gradio"
)

# Launch the interface
iface.launch()