Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,56 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
import base64
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
# Make the API call
|
25 |
-
response = client.chat.completions.create(
|
26 |
-
model="meta-llama/Llama-Vision-Free",
|
27 |
-
messages=messages,
|
28 |
-
max_tokens=512,
|
29 |
-
temperature=0.7,
|
30 |
-
top_p=0.7,
|
31 |
-
top_k=50,
|
32 |
-
repetition_penalty=1,
|
33 |
-
stop=["<|eot_id|>", "<|eom_id|>"]
|
34 |
-
)
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
html_output = f"""
|
41 |
-
<pre><code class="language-python">{generated_code}</code></pre>
|
42 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
|
43 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
|
44 |
-
<script>hljs.highlightAll();</script>
|
45 |
-
"""
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
inputs=gr.Image(type="pil"),
|
53 |
-
outputs=gr.HTML(),
|
54 |
-
title="Llama Vision Free Code Generation",
|
55 |
-
description="Upload an image, and this demo will use the Llama Vision Free model to analyze it and generate relevant Python code."
|
56 |
-
)
|
57 |
|
58 |
-
|
59 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
|
|
3 |
|
4 |
+
def generate_app(image):
|
5 |
+
# Placeholder function for app generation
|
6 |
+
# In a real scenario, this would involve image analysis and code generation
|
7 |
+
components = ["Header", "Sidebar", "MainContent", "Footer"]
|
8 |
+
code = f"""
|
9 |
+
import React from 'react';
|
10 |
+
import {{ {', '.join(components)} }} from './components';
|
11 |
|
12 |
+
function App() {{
|
13 |
+
return (
|
14 |
+
<div className="app">
|
15 |
+
{' '.join(f'<{component} />' for component in components)}
|
16 |
+
</div>
|
17 |
+
);
|
18 |
+
}}
|
19 |
+
|
20 |
+
export default App;
|
21 |
+
"""
|
22 |
+
return code
|
23 |
+
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("# Turn your wireframe into an app")
|
26 |
+
gr.Markdown("Upload an image of your website design and we'll build it for you with React + Tailwind.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column(scale=2):
|
30 |
+
with gr.Row():
|
31 |
+
napkin_img = gr.Image(value="path/to/napkin_sketch.png", label="Napkin")
|
32 |
+
react_img = gr.Image(value="path/to/react_app.png", label="React app")
|
33 |
+
|
34 |
+
file_output = gr.File(label="Download React App")
|
35 |
+
|
36 |
+
with gr.Column():
|
37 |
+
image_input = gr.Image(label="Upload a screenshot", elem_id="image_upload")
|
38 |
+
example_link = gr.Markdown("Need an example image? [Try ours](#).")
|
39 |
+
|
40 |
+
model_dropdown = gr.Dropdown(
|
41 |
+
choices=["Llama 3.2 90B Vision", "Other models..."],
|
42 |
+
value="Llama 3.2 90B Vision",
|
43 |
+
label="AI Model"
|
44 |
+
)
|
45 |
+
|
46 |
+
generate_button = gr.Button("Generate app", variant="primary")
|
47 |
|
48 |
+
code_output = gr.Code(language="javascript", label="Generated React Code")
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
generate_button.click(
|
51 |
+
fn=generate_app,
|
52 |
+
inputs=[image_input],
|
53 |
+
outputs=[code_output, file_output]
|
54 |
+
)
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
demo.launch()
|
|