| | import gradio as gr |
| | from transformers import AutoTokenizer, AutoModelForCausalLM |
| | import torch |
| |
|
| | |
| | model_name = "SJSui/AstroBot" |
| | tokenizer = AutoTokenizer.from_pretrained(model_name) |
| | model = AutoModelForCausalLM.from_pretrained(model_name) |
| |
|
| | |
| | def generate_text(prompt): |
| | inputs = tokenizer(prompt, return_tensors="pt") |
| | with torch.no_grad(): |
| | output = model.generate(**inputs, max_length=100) |
| | return tokenizer.decode(output[0], skip_special_tokens=True) |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=generate_text, |
| | inputs=gr.Textbox(label="Enter your prompt"), |
| | outputs=gr.Textbox(label="Generated Response"), |
| | title="AstroBot AI Chat", |
| | description="This is a chatbot powered by the AstroBot model.", |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | iface.launch() |
| |
|