mroccuper commited on
Commit
c71c76a
·
verified ·
1 Parent(s): 9b46468

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+
4
+ def hex_to_words(api_key, hex_input):
5
+ # Initialize Gemini with API key
6
+ try:
7
+ genai.configure(api_key=api_key)
8
+ model = genai.GenerativeModel('gemini-1.5-pro')
9
+ except Exception as e:
10
+ return f"Error with API key or model: {str(e)}"
11
+
12
+ prompt = f"Convert the following hex color codes to their closest color names. Don't worry about exact matches. Example format: #ffc0cb #0000FF → pink blue\n\nNow convert:\n{hex_input}\nOnly return the color names."
13
+
14
+ try:
15
+ response = model.generate_content(prompt)
16
+ return response.text.strip()
17
+ except Exception as e:
18
+ return f"Error generating response: {str(e)}"
19
+
20
+ # Gradio UI
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("## 🎨 Hex Color to Word with Gemini 1.5 Pro")
23
+
24
+ api_key_input = gr.Textbox(label="Gemini API Key", type="password", placeholder="Enter your Gemini 1.5 Pro API key")
25
+ hex_input = gr.Textbox(label="Hex Color Input", placeholder="#ffc0cb #0000FF #008000")
26
+ output = gr.Textbox(label="Output (Color Words)")
27
+
28
+ btn = gr.Button("Submit")
29
+ btn.click(fn=hex_to_words, inputs=[api_key_input, hex_input], outputs=output)
30
+
31
+ demo.launch()