Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import base64
|
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
# Initialize the Together client
|
10 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
@@ -25,28 +26,29 @@ def generate_gradio_app(image):
|
|
25 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
26 |
|
27 |
# Prepare the message for the API call
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Make the API call
|
34 |
-
response = client.chat.completions.create(
|
35 |
-
model="meta-llama/Llama-Vision-Free",
|
36 |
-
messages=[{"role": "user", "content": message}],
|
37 |
-
max_tokens=512,
|
38 |
-
temperature=0.7,
|
39 |
-
top_p=0.7,
|
40 |
-
top_k=50,
|
41 |
-
repetition_penalty=1,
|
42 |
-
stop=["<|eot_id|>", "<|eom_id|>"],
|
43 |
-
stream=True
|
44 |
-
)
|
45 |
|
46 |
# Collect the streamed response
|
47 |
generated_text = ""
|
48 |
for chunk in response:
|
49 |
-
if chunk.choices[0].delta.content
|
50 |
generated_text += chunk.choices[0].delta.content
|
51 |
|
52 |
return generated_text
|
|
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
8 |
+
import json
|
9 |
|
10 |
# Initialize the Together client
|
11 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
|
|
26 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
27 |
|
28 |
# Prepare the message for the API call
|
29 |
+
message_content = f"""<image>{img_str}</image>
|
30 |
+
Analyze this wireframe image and suggest a simple Gradio app layout based on it. Describe the main elements you see and how they could be implemented using Gradio components."""
|
31 |
+
|
32 |
+
# Prepare the API request payload
|
33 |
+
payload = {
|
34 |
+
"model": "meta-llama/Llama-Vision-Free",
|
35 |
+
"messages": [{"role": "user", "content": message_content}],
|
36 |
+
"max_tokens": 512,
|
37 |
+
"temperature": 0.7,
|
38 |
+
"top_p": 0.7,
|
39 |
+
"top_k": 50,
|
40 |
+
"repetition_penalty": 1,
|
41 |
+
"stop": ["<|eot_id|>", "<|eom_id|>"],
|
42 |
+
"stream_tokens": True
|
43 |
+
}
|
44 |
|
45 |
# Make the API call
|
46 |
+
response = client.chat.completions.create(**payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# Collect the streamed response
|
49 |
generated_text = ""
|
50 |
for chunk in response:
|
51 |
+
if chunk.choices and chunk.choices[0].delta.content:
|
52 |
generated_text += chunk.choices[0].delta.content
|
53 |
|
54 |
return generated_text
|