Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
print("Loading model...")
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def chat(message, history):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
fn=chat,
|
| 21 |
title="✨ Aura — поэтичная модель",
|
| 22 |
description="Пишите по-русски, модель отвечает на русском"
|
| 23 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import sys
|
| 4 |
|
| 5 |
+
print("Loading model...", flush=True)
|
| 6 |
+
try:
|
| 7 |
+
pipe = pipeline(
|
| 8 |
+
"text-generation",
|
| 9 |
+
model="Andrewstivan/AURA",
|
| 10 |
+
device=-1,
|
| 11 |
+
trust_remote_code=True
|
| 12 |
+
)
|
| 13 |
+
print("Model loaded successfully!", flush=True)
|
| 14 |
+
except Exception as e:
|
| 15 |
+
print(f"Error loading model: {e}", flush=True)
|
| 16 |
+
sys.exit(1)
|
| 17 |
|
| 18 |
def chat(message, history):
|
| 19 |
+
if not message:
|
| 20 |
+
return ""
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
result = pipe(
|
| 24 |
+
message,
|
| 25 |
+
max_new_tokens=300,
|
| 26 |
+
temperature=0.8,
|
| 27 |
+
do_sample=True,
|
| 28 |
+
truncation=True,
|
| 29 |
+
max_length=512
|
| 30 |
+
)
|
| 31 |
+
return result[0]["generated_text"]
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Ошибка: {e}"
|
| 34 |
|
| 35 |
+
|
| 36 |
+
demo = gr.ChatInterface(
|
| 37 |
fn=chat,
|
| 38 |
title="✨ Aura — поэтичная модель",
|
| 39 |
description="Пишите по-русски, модель отвечает на русском"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
demo.launch(
|
| 43 |
+
server_name="0.0.0.0",
|
| 44 |
+
server_port=7860,
|
| 45 |
+
share=False
|
| 46 |
+
)
|