Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
message,
|
| 10 |
-
history: list[tuple[str, str]],
|
| 11 |
-
system_message,
|
| 12 |
-
max_tokens,
|
| 13 |
-
temperature,
|
| 14 |
-
top_p,
|
| 15 |
-
):
|
| 16 |
-
|
| 17 |
-
prompt = system_message + "\n"
|
| 18 |
-
|
| 19 |
-
for user_input, bot_response in history:
|
| 20 |
-
if user_input:
|
| 21 |
-
prompt += f"User: {user_input}\n"
|
| 22 |
-
if bot_response:
|
| 23 |
-
prompt += f"Assistant: {bot_response}\n"
|
| 24 |
-
|
| 25 |
-
prompt += f"User: {message}\nAssistant:"
|
| 26 |
-
|
| 27 |
-
response = llm(
|
| 28 |
-
prompt,
|
| 29 |
-
max_tokens=max_tokens,
|
| 30 |
-
temperature=temperature,
|
| 31 |
-
top_p=top_p,
|
| 32 |
)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
],
|
|
|
|
|
|
|
|
|
|
| 52 |
)
|
| 53 |
|
|
|
|
| 54 |
if __name__ == "__main__":
|
| 55 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from ctransformers import AutoModelForCausalLM
|
| 3 |
|
| 4 |
+
def load_model():
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 6 |
+
"Llight.Q8_0.gguf",
|
| 7 |
+
model_type="llama",
|
| 8 |
+
gpu_layers=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
)
|
| 10 |
+
return model
|
| 11 |
+
|
| 12 |
+
def generate_response(prompt, max_tokens=128, temperature=0.7):
|
| 13 |
+
try:
|
| 14 |
+
model = load_model()
|
| 15 |
+
response = model(
|
| 16 |
+
prompt,
|
| 17 |
+
max_tokens=max_tokens,
|
| 18 |
+
temperature=temperature
|
| 19 |
+
)
|
| 20 |
+
return response
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Произошла ошибка: {str(e)}"
|
| 23 |
+
|
| 24 |
+
# Создаем интерфейс
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=generate_response,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Textbox(label="Введите ваш запрос", lines=3),
|
| 29 |
+
gr.Slider(minimum=1, maximum=512, value=128, label="Max Tokens"),
|
| 30 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, label="Temperature"),
|
| 31 |
],
|
| 32 |
+
outputs=gr.Textbox(label="Ответ модели", lines=5),
|
| 33 |
+
title="LLight Model Demo",
|
| 34 |
+
description="Демонстрация работы GGUF модели"
|
| 35 |
)
|
| 36 |
|
| 37 |
+
# Запускаем приложение
|
| 38 |
if __name__ == "__main__":
|
| 39 |
demo.launch()
|