Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,40 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Gradio interface
|
| 44 |
-
with gr.Blocks() as demo:
|
| 45 |
-
gr.HTML("<h2 style='text-align:center'>Airi — Mini Chat AI</h2>")
|
| 46 |
-
gr.HTML("<p style='text-align:center;color:#666;'>Small, Fast & Public Model</p>")
|
| 47 |
-
|
| 48 |
-
chat = gr.Chatbot()
|
| 49 |
-
msg = gr.Textbox(label="Talk to Airi…", placeholder="Write here…")
|
| 50 |
-
msg.submit(chat_with_airi, msg, [chat, msg])
|
| 51 |
-
|
| 52 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the chatbot model (publicly available, no auth needed)
|
| 5 |
+
# Using a lightweight model for fast responses
|
| 6 |
+
model_id = "facebook/blenderbot-400M-distill"
|
| 7 |
+
chatbot = pipeline("conversational", model=model_id)
|
| 8 |
+
|
| 9 |
+
def chat_function(message, history):
|
| 10 |
+
"""
|
| 11 |
+
Simple chat function that takes user input and returns AI response
|
| 12 |
+
"""
|
| 13 |
+
# Convert history to format expected by the model
|
| 14 |
+
conversation = []
|
| 15 |
+
for human, ai in history:
|
| 16 |
+
conversation.append({"role": "user", "content": human})
|
| 17 |
+
conversation.append({"role": "assistant", "content": ai})
|
| 18 |
+
|
| 19 |
+
conversation.append({"role": "user", "content": message})
|
| 20 |
+
|
| 21 |
+
# Generate response
|
| 22 |
+
response = chatbot(conversation)
|
| 23 |
+
return response[-1]["content"]
|
| 24 |
+
|
| 25 |
+
# Create the chat interface
|
| 26 |
+
demo = gr.ChatInterface(
|
| 27 |
+
fn=chat_function,
|
| 28 |
+
title="airi",
|
| 29 |
+
description="A friendly AI assistant ready to chat with you!",
|
| 30 |
+
theme=gr.themes.Soft(),
|
| 31 |
+
examples=[
|
| 32 |
+
"Hello! How are you?",
|
| 33 |
+
"Tell me something interesting",
|
| 34 |
+
"What's your favorite topic?"
|
| 35 |
+
],
|
| 36 |
+
cache_examples=False,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|