|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<meta charset="utf-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
<title>Gradio-Lite: Serverless Gradio Running Entirely in Your Browser</title> |
|
<meta name="description" content="Gradio-Lite: Serverless Gradio Running Entirely in Your Browser"> |
|
|
|
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script> |
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" /> |
|
|
|
<style> |
|
html, body { |
|
margin: 0; |
|
padding: 0; |
|
height: 100%; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<gradio-lite> |
|
<gradio-file name="app.py" entrypoint> |
|
import gradio as gr |
|
from js import self |
|
|
|
session = None |
|
try: |
|
can_ai_create = await self.ai.canCreateTextSession() |
|
if can_ai_create != "no": |
|
session = await self.ai.createTextSession() |
|
except: |
|
pass |
|
|
|
|
|
self.ai_text_session = session |
|
|
|
|
|
async def prompt(message, history): |
|
session = self.ai_text_session |
|
if not session: |
|
raise Exception("Gemini Nano is not available in your browser.") |
|
|
|
stream = session.promptStreaming(message) |
|
async for chunk in stream: |
|
yield chunk |
|
|
|
|
|
demo = gr.ChatInterface(fn=prompt) |
|
|
|
demo.launch() |
|
|
|
</gradio-file> |
|
|
|
<gradio-requirements> |
|
transformers-js-py |
|
</gradio-requirements> |
|
</gradio-lite> |
|
</body> |
|
</html> |