File size: 967 Bytes
7048b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, GPT2Config
import torch

# Load the OpenBuddy model and tokenizer
model_name = "OpenBuddy/openbuddy-7b-v1.3-q4_0-enc"
tokenizer = AutoTokenizer.from_pretrained(model_name)
config = GPT2Config()  # Use default configuration
model = AutoModelForCausalLM.from_pretrained(model_name, config=config)

# Create a function to generate responses from user inputs
def generate_response(input_text):
    input_ids = tokenizer.encode(input_text, return_tensors="pt")
    output = model.generate(input_ids, max_length=100, pad_token_id=tokenizer.eos_token_id)
    response = tokenizer.decode(output[0], skip_special_tokens=True)
    return response

# Define the Gradio interface
iface = gr.Interface(
    fn=generate_response,
    inputs="text",
    outputs="text",
    title="OpenBuddy Chat",
    description="Enter your message to chat with OpenBuddy."
)

# Launch the interface
iface.launch()