Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 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
|
|
@@ -13,23 +13,28 @@ pipe = pipeline("text-generation", model=model_name, device="cpu")
|
|
| 13 |
system_prompt = {"role": "system", "content": "Ты — ИИ-помощник. Тебе дано задание: необходимо сгенерировать подробный и развернутый ответ."}
|
| 14 |
|
| 15 |
# Define the Gradio interface
|
| 16 |
-
def generate_response(user_input):
|
| 17 |
-
messages = [
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return
|
| 23 |
|
| 24 |
# Create the Gradio interface
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Launch the interface
|
| 34 |
if __name__ == "__main__":
|
| 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 with chat and token streaming functionality.
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from transformers import pipeline
|
|
|
|
| 13 |
system_prompt = {"role": "system", "content": "Ты — ИИ-помощник. Тебе дано задание: необходимо сгенерировать подробный и развернутый ответ."}
|
| 14 |
|
| 15 |
# Define the Gradio interface
|
| 16 |
+
def generate_response(history, user_input):
|
| 17 |
+
messages = [system_prompt] + history + [{"role": "user", "content": user_input}]
|
| 18 |
+
response = pipe(messages, max_length=1024, return_full_text=False)
|
| 19 |
+
generated_text = response[0]['generated_text']
|
| 20 |
+
history.append({"role": "user", "content": user_input})
|
| 21 |
+
history.append({"role": "assistant", "content": generated_text})
|
| 22 |
+
return history, ""
|
| 23 |
|
| 24 |
# Create the Gradio interface
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("## Cotype-Nano Text Generation Chat")
|
| 27 |
+
|
| 28 |
+
chatbot = gr.Chatbot([], elem_id="chatbot")
|
| 29 |
+
|
| 30 |
+
with gr.Row():
|
| 31 |
+
txt = gr.Textbox(
|
| 32 |
+
show_label=False,
|
| 33 |
+
placeholder="Введите ваш запрос здесь...",
|
| 34 |
+
).style(container=False)
|
| 35 |
+
|
| 36 |
+
txt.submit(generate_response, [chatbot, txt], [chatbot, txt])
|
| 37 |
|
| 38 |
# Launch the interface
|
| 39 |
if __name__ == "__main__":
|
| 40 |
+
demo.launch()
|