Spaces:
Runtime error
Runtime error
Commit
·
4e130e4
1
Parent(s):
ce91428
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,24 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
# Use replicate to run the model
|
| 13 |
-
output = replicate.run(
|
| 14 |
-
"stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2",
|
| 15 |
-
input={"prompt": prompt}
|
| 16 |
-
)
|
| 17 |
-
return output
|
| 18 |
-
|
| 19 |
-
# Create the Gradio interface
|
| 20 |
-
iface = gr.Interface(
|
| 21 |
-
fn=run_replicate,
|
| 22 |
-
inputs=gr.inputs.Textbox(placeholder="Enter your prompt..."),
|
| 23 |
-
outputs="text"
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# Launch the Gradio interface
|
| 27 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Create a Gradio interface
|
| 6 |
+
def caption_image(input_image):
|
| 7 |
+
|
| 8 |
+
caption_model_url = "Salesforce/blip-image-captioning-large"
|
| 9 |
+
files = {"file": open(input_image.name, "rb")}
|
| 10 |
+
response = requests.post(caption_model_url, files=files)
|
| 11 |
+
caption = response.json()["caption"]
|
| 12 |
+
|
| 13 |
+
# Use the Transformers pipeline for sentiment analysis
|
| 14 |
+
sentiment_model = pipeline("sentiment-analysis")
|
| 15 |
+
sentiment_score = sentiment_model(caption)[0]["label"]
|
| 16 |
+
|
| 17 |
+
return f"Caption: {caption}\nSentiment: {sentiment_score}"
|
| 18 |
|
| 19 |
+
# Define the Gradio input interface
|
| 20 |
+
inputs = gr.inputs.Image()
|
| 21 |
+
output = gr.outputs.Textbox()
|
| 22 |
|
| 23 |
+
# Launch the Gradio app
|
| 24 |
+
gr.Interface(fn=caption_image, inputs=inputs, outputs=output, live=True).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|