File size: 1,194 Bytes
1366879
b087f1f
1366879
b087f1f
 
 
 
 
 
eb9e49c
b087f1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1366879
b087f1f
 
 
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
31
32
33
34
35
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the model and tokenizer
model_name = "CatGPT"  # Replace with the exact model name if necessary
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Define the chat function
def chat(input_text):
    try:
        # Tokenize the input
        inputs = tokenizer(input_text, return_tensors="pt")
        
        # Generate a response from the model
        outputs = model.generate(**inputs, max_length=150)
        
        # Decode and return the response
        response = tokenizer.decode(outputs[0], skip_special_tokens=True)
        return response

    except Exception as e:
        return f"An error occurred: {str(e)}"

# Create the Gradio interface
iface = gr.Interface(fn=chat, 
                     inputs=gr.inputs.Textbox(lines=7, label="Enter your message"),
                     outputs=gr.outputs.Textbox(label="Response"),
                     title="CatGPT - Chatbot",
                     description="Chat with CatGPT, a fun and intelligent chatbot!")

# Launch the interface
if __name__ == "__main__":
    iface.launch()