secsplorer / modal_gradio_test.py
lagerbaer's picture
Upload folder using huggingface_hub
bcf7c58 verified
from modal import Stub, Image, asgi_app
from fastapi import FastAPI
image = (
Image.debian_slim()
.run_commands(["pip install --upgrade pip"])
.pip_install(
"gradio",
)
)
stub = Stub("secsplorer", image=image)
web_app = FastAPI()
@stub.function()
@asgi_app()
def fastapi_app():
import gradio as gr
from gradio.routes import mount_gradio_app
import gradio as gr
import random
import time
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
print("Calling respond...")
bot_message = random.choice(
["How are you?", "I love you", "I'm very hungry"]
)
chat_history.append((message, bot_message))
print("Returning result...")
yield "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
mount_gradio_app(app=web_app, blocks=demo, path="/")
return web_app