Spaces:
Sleeping
Sleeping
| """ | |
| ui.py - Nexari Chat Interface | |
| Description: Handles the Gradio UI layout and styling. | |
| """ | |
| import gradio as gr | |
| import asyncio | |
| def create_ui(generate_fn): | |
| """ | |
| generate_fn: An async function that takes 'messages' (list of dicts) | |
| and yields strings (stream). | |
| """ | |
| async def chat_wrapper(message, history): | |
| messages = [] | |
| # Convert Gradio history [[user, bot], ...] to OpenAI format | |
| for human, ai in history: | |
| messages.append({"role": "user", "content": human}) | |
| messages.append({"role": "assistant", "content": ai}) | |
| messages.append({"role": "user", "content": message}) | |
| # Consume the async generator | |
| partial_response = "" | |
| async for chunk in generate_fn(messages): | |
| partial_response = chunk | |
| yield partial_response | |
| # Custom CSS | |
| custom_css = """ | |
| body { background-color: #0b0f19; color: #e0e0e0; } | |
| .gradio-container { font-family: 'Inter', sans-serif; max-width: 900px !important; margin: auto; } | |
| footer { visibility: hidden; display: none; } | |
| """ | |
| demo = gr.ChatInterface( | |
| fn=chat_wrapper, | |
| title="Nexari AI", | |
| description="Official Backend for Nexari Research. Powered by Nexari-Qwen-3B.", | |
| theme="soft", | |
| examples=[ | |
| "Who created you?", | |
| "Explain Quantum Computing in simple terms", | |
| "Write a Python script to scrape a website" | |
| ], | |
| css=custom_css, | |
| concurrency_limit=5 | |
| ) | |
| return demo | |