Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
-
import spaces
|
| 6 |
|
| 7 |
# Load the processor and model
|
| 8 |
processor = AutoProcessor.from_pretrained(
|
|
@@ -19,7 +18,6 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 19 |
device_map='auto'
|
| 20 |
)
|
| 21 |
|
| 22 |
-
@spaces.GPU(duration=120)
|
| 23 |
def process_image_and_text(image, text):
|
| 24 |
# Process the image and text
|
| 25 |
inputs = processor.process(
|
|
@@ -45,11 +43,11 @@ def process_image_and_text(image, text):
|
|
| 45 |
|
| 46 |
def chatbot(image, text, history):
|
| 47 |
if image is None:
|
| 48 |
-
return "Please upload an image first.",
|
| 49 |
|
| 50 |
response = process_image_and_text(image, text)
|
| 51 |
history.append((text, response))
|
| 52 |
-
return
|
| 53 |
|
| 54 |
# Define the Gradio interface
|
| 55 |
with gr.Blocks() as demo:
|
|
@@ -67,13 +65,13 @@ with gr.Blocks() as demo:
|
|
| 67 |
submit_button.click(
|
| 68 |
chatbot,
|
| 69 |
inputs=[image_input, text_input, state],
|
| 70 |
-
outputs=[chatbot_output
|
| 71 |
)
|
| 72 |
|
| 73 |
text_input.submit(
|
| 74 |
chatbot,
|
| 75 |
inputs=[image_input, text_input, state],
|
| 76 |
-
outputs=[chatbot_output
|
| 77 |
)
|
| 78 |
|
| 79 |
demo.launch()
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
|
|
|
| 5 |
|
| 6 |
# Load the processor and model
|
| 7 |
processor = AutoProcessor.from_pretrained(
|
|
|
|
| 18 |
device_map='auto'
|
| 19 |
)
|
| 20 |
|
|
|
|
| 21 |
def process_image_and_text(image, text):
|
| 22 |
# Process the image and text
|
| 23 |
inputs = processor.process(
|
|
|
|
| 43 |
|
| 44 |
def chatbot(image, text, history):
|
| 45 |
if image is None:
|
| 46 |
+
return history + [("Please upload an image first.", None)]
|
| 47 |
|
| 48 |
response = process_image_and_text(image, text)
|
| 49 |
history.append((text, response))
|
| 50 |
+
return history
|
| 51 |
|
| 52 |
# Define the Gradio interface
|
| 53 |
with gr.Blocks() as demo:
|
|
|
|
| 65 |
submit_button.click(
|
| 66 |
chatbot,
|
| 67 |
inputs=[image_input, text_input, state],
|
| 68 |
+
outputs=[chatbot_output]
|
| 69 |
)
|
| 70 |
|
| 71 |
text_input.submit(
|
| 72 |
chatbot,
|
| 73 |
inputs=[image_input, text_input, state],
|
| 74 |
+
outputs=[chatbot_output]
|
| 75 |
)
|
| 76 |
|
| 77 |
demo.launch()
|