Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
import torch | |
# Load the model and tokenizer | |
model_name = "indonlp/cendol-llama2-7b-chat" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
# Define the chatbot function | |
def chatbot(input_text): | |
inputs = tokenizer(input_text, return_tensors="pt") | |
with torch.no_grad(): | |
outputs = model.generate(inputs.input_ids, max_length=1000, do_sample=True) | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# Create the Gradio interface | |
interface = gr.ChatInterface( | |
fn=chatbot, | |
title="Cendol Chatnot", | |
description="Ask any coding-related questions and get helpful responses." | |
) | |
# Launch the web UI | |
interface.launch(share=True) | |