Create Appy
Browse files
Appy
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Alegem un model AI open-source gratuit
|
| 6 |
+
model_name = "mistralai/Mistral-7B-Instruct" # Poți schimba cu un alt model
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 9 |
+
|
| 10 |
+
def chat(user_input):
|
| 11 |
+
inputs = tokenizer(user_input, return_tensors="pt").to("cuda")
|
| 12 |
+
output = model.generate(**inputs, max_length=300)
|
| 13 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
# Creăm interfața web
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=chat,
|
| 19 |
+
inputs=gr.Textbox(lines=5, placeholder="Scrie aici..."),
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="NanAI Scribo",
|
| 22 |
+
description="Chatbot AI specializat în metafizică, filozofie și terapii holistice."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
iface.launch()
|