Cotype-Nano / app.py
Ivan000's picture
Create app.py
2df152f verified
raw
history blame
1.25 kB
# app.py
# =============
# This is a complete app.py file for deploying the MTSAIR/Cotype-Nano model using Gradio and Hugging Face Transformers.
import gradio as gr
from transformers import pipeline
# Load the model and pipeline
model_name = "MTSAIR/Cotype-Nano"
pipe = pipeline("text-generation", model=model_name, device="cpu")
# Define the system prompt
system_prompt = {"role": "system", "content": "Ты — ИИ-помощник. Тебе дано задание: необходимо сгенерировать подробный и развернутый ответ."}
# Define the Gradio interface
def generate_response(user_input):
messages = [
system_prompt,
{"role": "user", "content": user_input}
]
response = pipe(messages, max_length=1024)
return response[0]['generated_text']
# Create the Gradio interface
iface = gr.Interface(
fn=generate_response,
inputs=gr.inputs.Textbox(lines=2, placeholder="Введите ваш запрос здесь..."),
outputs="text",
title="Cotype-Nano Text Generation",
description="Введите ваш запрос, и Cotype-Nano сгенерирует ответ."
)
# Launch the interface
if __name__ == "__main__":
iface.launch()