|
|
import gradio as gr |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
import torch |
|
|
|
|
|
|
|
|
model_name = "mistralai/Mistral-7B-Instruct" # Poți schimba cu un alt model |
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto") |
|
|
|
|
|
def chat(user_input): |
|
|
inputs = tokenizer(user_input, return_tensors="pt").to("cuda") |
|
|
output = model.generate(**inputs, max_length=300) |
|
|
response = tokenizer.decode(output[0], skip_special_tokens=True) |
|
|
return response |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=chat, |
|
|
inputs=gr.Textbox(lines=5, placeholder="Scrie aici..."), |
|
|
outputs="text", |
|
|
title="NanAI Scribo", |
|
|
description="Chatbot AI specializat în metafizică, filozofie și terapii holistice." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|