JaweriaGenAI commited on
Commit
279522e
·
verified ·
1 Parent(s): ce08c42

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ # Get API key from Hugging Face secrets
6
+ genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
+ model = genai.GenerativeModel("gemini-pro")
8
+
9
+ def gemini_chat(user_input):
10
+ try:
11
+ if not user_input.strip():
12
+ return "Please type something."
13
+ response = model.generate_content(user_input)
14
+ return response.text
15
+ except Exception as e:
16
+ return f"⚠️ Error: {str(e)}"
17
+
18
+ with gr.Blocks(css="""
19
+ .gradio-container { max-width: 700px; margin: auto; font-family: 'Segoe UI', sans-serif; }
20
+ .title { font-size: 2em; color: white; background-color: #1f2937; padding: 20px; border-radius: 12px; text-align: center; margin-bottom: 10px; }
21
+ .textbox { border-radius: 12px; }
22
+ """) as demo:
23
+
24
+ gr.Markdown("<div class='title'>🤖 Welcome to Jaweria'sBot</div>")
25
+
26
+ with gr.Row():
27
+ user_input = gr.Textbox(placeholder="Type your message here...", lines=2, label="You", elem_classes=["textbox"])
28
+
29
+ submit_btn = gr.Button("Send", variant="primary")
30
+ response_output = gr.Textbox(label="Jaweria'sBot", interactive=False, lines=6, elem_classes=["textbox"])
31
+
32
+ submit_btn.click(fn=gemini_chat, inputs=user_input, outputs=response_output)
33
+
34
+ demo.launch()