Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
model_id = "bczhou/tiny-llava-v1-hf"
|
| 5 |
+
pipe = pipeline("image-to-text", model=model_id)
|
| 6 |
+
|
| 7 |
+
def generate_text(prompt, image):
|
| 8 |
+
# Generate text description
|
| 9 |
+
prompt = f"USER: <image>\n{prompt}\nASSISTANT:"
|
| 10 |
+
text_description = pipe(images=image, prompt=prompt,generate_kwargs={"max_new_tokens": 200})) # Batch for efficiency
|
| 11 |
+
return text_description[0]
|
| 12 |
+
|
| 13 |
+
# Create Gradio interface
|
| 14 |
+
inputs = [gr.Textbox(label="Input Text"), gr.Image(type="pil")] # Input for uploading an image
|
| 15 |
+
outputs = gr.Textbox(label="Generated Text") # Output for displaying the text
|
| 16 |
+
|
| 17 |
+
# Create the interface
|
| 18 |
+
interface = gr.Interface(fn=generate_text, inputs=inputs, outputs=outputs, title="LLaVa Image-to-Text")
|
| 19 |
+
|
| 20 |
+
# Launch the interface
|
| 21 |
+
interface.launch()
|