Spaces:
Sleeping
Sleeping
File size: 1,347 Bytes
a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb a3baa6a f55bfeb |
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 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model & tokenizer
MODEL_NAME = "ubiodee/Cardano_plutus"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
model.eval()
if torch.cuda.is_available():
model.to("cuda")
# Response function
def generate_response(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=200,
temperature=0.7,
top_p=0.9,
do_sample=True,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Remove the prompt from the output to return only the answer
if response.startswith(prompt):
response = response[len(prompt):].strip()
return response
# Gradio UI
demo = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(label="Enter your prompt", lines=4, placeholder="Ask about Plutus..."),
outputs=gr.Textbox(label="Model Response"),
title="Cardano Plutus AI Assistant",
description="Ask questions about Plutus smart contracts or Cardano blockchain."
)
demo.launch()
|