ui created with gradio
Browse files- .env.example +1 -0
- app.py +33 -0
- branding.json +26 -0
- chatbot.py +29 -0
- prompt.poml +25 -0
- requirements.txt +5 -0
.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GOOGLE_API_KEY=your_google_api_key_here from https://aistudio.google.com/apikey
|
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr # Import the Gradio library for building UIs
|
| 2 |
+
from chatbot import chatbot # Import the AI chatbot function from the app module
|
| 3 |
+
import json # Import the json library for handling JSON data
|
| 4 |
+
import os # Import the os library for interacting with the operating system
|
| 5 |
+
|
| 6 |
+
# Load branding data from the branding.json file
|
| 7 |
+
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'branding.json'))) as f:
|
| 8 |
+
brand_info = json.load(f)['brand']
|
| 9 |
+
|
| 10 |
+
# Create the Gradio interface using gr.Blocks for custom layout
|
| 11 |
+
with gr.Blocks(theme='default', title=brand_info['organizationName']) as demo:
|
| 12 |
+
# Embed the logo using HTML for centering and styling
|
| 13 |
+
gr.HTML(f'''<div style="display: flex; justify-content: center; margin-bottom: 20px;">
|
| 14 |
+
<img src="{brand_info['logo']['title']}" alt="{brand_info['organizationName']} Logo" style="height: 100px;">
|
| 15 |
+
</div>''')
|
| 16 |
+
# Create the chat interface with specified functions and branding
|
| 17 |
+
gr.ChatInterface(
|
| 18 |
+
fn=chatbot, # Function to call for chatbot responses
|
| 19 |
+
chatbot=gr.Chatbot(height=500, avatar_images=(None, brand_info['chatbot']['avatar']), type="messages"), # Configure chatbot display
|
| 20 |
+
title=brand_info['organizationName'], # Set the title of the chat interface
|
| 21 |
+
description=brand_info['slogan'], # Set the description/slogan
|
| 22 |
+
type="messages", # Specify the message format
|
| 23 |
+
examples=[
|
| 24 |
+
["What is AI?"],
|
| 25 |
+
["Can you explain machine learning?"],
|
| 26 |
+
["How does a neural network work?"],
|
| 27 |
+
["What is natural language processing?"],
|
| 28 |
+
] # Example prompts for the chatbot
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the Gradio interface when the script is executed
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch(favicon_path=brand_info['logo']['favicon']) # Launch the demo with the specified favicon path
|
branding.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"brand":
|
| 3 |
+
{
|
| 4 |
+
"organizationName": "HERE AND NOW AI",
|
| 5 |
+
"website": "https://hereandnowai.com",
|
| 6 |
+
"email": "info@hereandnowai.com",
|
| 7 |
+
"mobile": "+91 996 296 1000",
|
| 8 |
+
"slogan": "designed with passion for innovation",
|
| 9 |
+
"colors": {"primary": "#FFDF00", "secondary": "#004040"},
|
| 10 |
+
"logo":
|
| 11 |
+
{
|
| 12 |
+
"title": "https://raw.githubusercontent.com/hereandnowai/images/refs/heads/main/logos/logo-of-here-and-now-ai.png",
|
| 13 |
+
"favicon": "https://raw.githubusercontent.com/hereandnowai/images/refs/heads/main/logos/favicon-logo-with-name.png"}, "chatbot": {"avatar": "https://raw.githubusercontent.com/hereandnowai/images/refs/heads/main/logos/caramel.jpeg", "face": "https://raw.githubusercontent.com/hereandnowai/images/refs/heads/main/logos/caramel-face.jpeg"
|
| 14 |
+
},
|
| 15 |
+
|
| 16 |
+
"socialMedia":
|
| 17 |
+
{
|
| 18 |
+
"blog": "https://hereandnowai.com/blog",
|
| 19 |
+
"linkedin": "https://www.linkedin.com/company/hereandnowai/",
|
| 20 |
+
"instagram": "https://instagram.com/hereandnow_ai",
|
| 21 |
+
"github": "https://github.com/hereandnowai",
|
| 22 |
+
"x": "https://x.com/hereandnow_ai",
|
| 23 |
+
"youtube": "https://youtube.com/@hereandnow_ai"
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
chatbot.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
from poml.integration.langchain import LangchainPomlTemplate
|
| 3 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash-lite", temperature=0.7)
|
| 8 |
+
|
| 9 |
+
conversation_history = []
|
| 10 |
+
|
| 11 |
+
def chatbot(user_input, history=None):
|
| 12 |
+
global conversation_history
|
| 13 |
+
prompt = LangchainPomlTemplate.from_file("prompt.poml")
|
| 14 |
+
history_text = "\n".join([f"Human: {h['user']}\nAssistant: {h['bot']}" for h in conversation_history[-5:]])
|
| 15 |
+
context = {"question": user_input, "history": history_text}
|
| 16 |
+
chain = prompt | llm | StrOutputParser()
|
| 17 |
+
response = chain.invoke(context)
|
| 18 |
+
conversation_history.append({"user": user_input, "bot": response})
|
| 19 |
+
if len(conversation_history) > 10:
|
| 20 |
+
conversation_history.pop(0)
|
| 21 |
+
return response
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
while True:
|
| 25 |
+
user_input = input("You: ")
|
| 26 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 27 |
+
break
|
| 28 |
+
response = chatbot(user_input)
|
| 29 |
+
print(f"Bot: {response}")
|
prompt.poml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<poml>
|
| 2 |
+
<role>Your name is Caramel AI, built by HERE AND NOW AI. You are a French Teacher. You teach French to English speaking children who do not know any French.</role>
|
| 3 |
+
|
| 4 |
+
<task>
|
| 5 |
+
<list>Say that you are a friendly French teacher</list>
|
| 6 |
+
<list>Ask the user, what they want to learn in French and teach only that topic</list>
|
| 7 |
+
<list>Explain everything in simple English.</list>
|
| 8 |
+
<list>Keep your answers simple, concise, and explain the meaning of each word in English.</list>
|
| 9 |
+
<list>Remember previous conversations and build upon what the user has learned</list>
|
| 10 |
+
</task>
|
| 11 |
+
|
| 12 |
+
Previous conversation history:
|
| 13 |
+
{{ history }}
|
| 14 |
+
|
| 15 |
+
Current question: {{ question }}
|
| 16 |
+
|
| 17 |
+
<example>
|
| 18 |
+
Bonjour! Comment allez-vous?
|
| 19 |
+
Bonjour: Hello
|
| 20 |
+
Comment: How
|
| 21 |
+
allez-vous: are you going?
|
| 22 |
+
|
| 23 |
+
But the meaning of the sentence together: **how are you?**
|
| 24 |
+
</example>
|
| 25 |
+
</poml>
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python-dotenv
|
| 2 |
+
langchain-google-genai
|
| 3 |
+
langchain
|
| 4 |
+
poml
|
| 5 |
+
gradio
|