Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
|
| 5 |
+
# Initialize the Nebius OpenAI client
|
| 6 |
+
client = OpenAI(
|
| 7 |
+
base_url="https://api.studio.nebius.ai/v1/",
|
| 8 |
+
api_key=os.environ.get("NEBIUS_API_KEY"),
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Function to process input and return the response
|
| 12 |
+
def analyze_image(image_url):
|
| 13 |
+
response = client.chat.completions.create(
|
| 14 |
+
model="Qwen/Qwen2-VL-72B-Instruct",
|
| 15 |
+
messages=[
|
| 16 |
+
{
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": [
|
| 19 |
+
{"type": "text", "text": "What’s in this image?"},
|
| 20 |
+
{
|
| 21 |
+
"type": "image_url",
|
| 22 |
+
"image_url": {"url": image_url},
|
| 23 |
+
},
|
| 24 |
+
],
|
| 25 |
+
}
|
| 26 |
+
],
|
| 27 |
+
max_tokens=300,
|
| 28 |
+
)
|
| 29 |
+
# Extract and return the AI's response
|
| 30 |
+
return response.choices[0].get("message", {}).get("content", "No response found.")
|
| 31 |
+
|
| 32 |
+
# Create the Gradio interface
|
| 33 |
+
with gr.Blocks() as app:
|
| 34 |
+
gr.Markdown("# Image Analysis with Nebius OpenAI")
|
| 35 |
+
image_url_input = gr.Textbox(
|
| 36 |
+
label="Image URL",
|
| 37 |
+
placeholder="Enter an image URL for analysis",
|
| 38 |
+
)
|
| 39 |
+
output = gr.Textbox(
|
| 40 |
+
label="AI Response",
|
| 41 |
+
placeholder="The description of the image will appear here.",
|
| 42 |
+
)
|
| 43 |
+
submit_button = gr.Button("Analyze Image")
|
| 44 |
+
submit_button.click(analyze_image, inputs=image_url_input, outputs=output)
|
| 45 |
+
|
| 46 |
+
# Launch the app
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
app.launch()
|