BackendServer / app_gradio.py
Codegeass321's picture
HF Spaces
422431d
import gradio as gr
from api import app
import uvicorn
import threading
import time
# Create a simple Gradio interface
def create_interface():
with gr.Blocks(title="ChatDocxAI Backend") as interface:
gr.Markdown("# ChatDocxAI Backend")
gr.Markdown("""
This is the backend server for ChatDocxAI. It provides the following endpoints:
- `/upload` - Upload documents
- `/ask` - Ask questions about uploaded documents
The frontend should be configured to communicate with this backend.
""")
with gr.Row():
with gr.Column():
gr.Markdown("## Server Status")
status = gr.Textbox(value="Server is running", label="Status")
with gr.Row():
with gr.Column():
gr.Markdown("## API Documentation")
doc_link = gr.HTML(f"<a href='/docs' target='_blank'>View FastAPI Docs</a>")
return interface
# Function to start FastAPI in a separate thread
def start_fastapi():
uvicorn.run(app, host="0.0.0.0", port=7860)
# Start FastAPI in a separate thread
fastapi_thread = threading.Thread(target=start_fastapi)
fastapi_thread.daemon = True
fastapi_thread.start()
# Allow some time for FastAPI to start
time.sleep(2)
# Create and launch the Gradio interface
interface = create_interface()
# Launch the interface
if __name__ == "__main__":
interface.launch(server_port=7861) # Use a different port than FastAPI