Spaces:
Sleeping
Sleeping
File size: 2,170 Bytes
bf4a1fd 932d067 32887b7 bf4a1fd 932d067 32887b7 932d067 32887b7 932d067 32887b7 bf4a1fd 932d067 bf4a1fd 932d067 bf4a1fd 81bbc3f bf4a1fd 932d067 |
1 2 3 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import gradio as gr
from PIL import Image
import os
import sys
import logging
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler(sys.stdout)]
)
logger = logging.getLogger(__name__)
logger.info("Starting UK Public Transport Assistant app")
# Add error handling for module imports
try:
from llava_inference import LLaVAHelper
logger.info("Successfully imported LLaVAHelper")
except Exception as e:
logger.error(f"Failed to import LLaVAHelper: {e}")
logger.error("Stack trace:", exc_info=True)
model = None
else:
# Initialize model
try:
logger.info("Initializing LLaVA model...")
model = LLaVAHelper()
logger.info("LLaVA model initialized successfully")
except Exception as e:
logger.error(f"Failed to initialize LLaVA model: {e}")
logger.error("Stack trace:", exc_info=True)
model = None
def answer_question(image, question):
if model is None:
return "Model initialization failed. Please check server logs."
if image is None or question.strip() == "":
return "Please upload an image and enter a question."
try:
return model.generate_answer(image, question)
except Exception as e:
return f"Error processing request: {str(e)}"
# Create examples directory if it doesn't exist
os.makedirs("assets", exist_ok=True)
demo = gr.Interface(
fn=answer_question,
inputs=[
gr.Image(type="pil", label="Upload Public Transport Signage"),
gr.Textbox(label="Ask a question (e.g., 'When is the next train to London?')")
],
outputs=gr.Textbox(label="Answer"),
title="UK Public Transport Assistant",
description="Upload an image of UK public transport signage (like train timetables or metro maps), and ask a question related to it. Powered by LLaVA-1.5.",
# Fix examples format - either provide valid examples or set to None
examples=None # Remove examples to avoid format errors
)
if __name__ == "__main__":
demo.launch(share=True) # Added share=True to make it accessible on a public URL |