Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
# =============
|
3 |
+
# This is a complete app.py file for deploying the MTSAIR/Cotype-Nano model using Gradio and Hugging Face Transformers.
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# Load the model and pipeline
|
9 |
+
model_name = "MTSAIR/Cotype-Nano"
|
10 |
+
pipe = pipeline("text-generation", model=model_name, device="cpu")
|
11 |
+
|
12 |
+
# Define the system prompt
|
13 |
+
system_prompt = {"role": "system", "content": "Ты — ИИ-помощник. Тебе дано задание: необходимо сгенерировать подробный и развернутый ответ."}
|
14 |
+
|
15 |
+
# Define the Gradio interface
|
16 |
+
def generate_response(user_input):
|
17 |
+
messages = [
|
18 |
+
system_prompt,
|
19 |
+
{"role": "user", "content": user_input}
|
20 |
+
]
|
21 |
+
response = pipe(messages, max_length=1024)
|
22 |
+
return response[0]['generated_text']
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate_response,
|
27 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Введите ваш запрос здесь..."),
|
28 |
+
outputs="text",
|
29 |
+
title="Cotype-Nano Text Generation",
|
30 |
+
description="Введите ваш запрос, и Cotype-Nano сгенерирует ответ."
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the interface
|
34 |
+
if __name__ == "__main__":
|
35 |
+
iface.launch()
|