|
import os |
|
import gradio as gr |
|
import openai |
|
from langdetect import detect |
|
|
|
|
|
openai.api_key = os.getenv("API_KEY") |
|
openai.api_base = "https://api.groq.com/openai/v1" |
|
|
|
|
|
from datasets.company_profile import company_profile |
|
from datasets.workforce import workforce |
|
from datasets.financials import financials |
|
from datasets.investors import investors |
|
from datasets.products_services import products_services |
|
from datasets.market_trends import market_trends |
|
from datasets.partnerships_collaborations import partnerships_collaborations |
|
from datasets.legal_compliance import legal_compliance |
|
from datasets.customer_insights import customer_insights |
|
from datasets.news_updates import news_updates |
|
from datasets.social_media import social_media |
|
from datasets.tech_stack import tech_stack |
|
|
|
|
|
def command_handler(user_input): |
|
if user_input.lower().startswith("define "): |
|
term = user_input[7:].strip() |
|
definitions = { |
|
"market analysis": ( |
|
"Market analysis is like peeking into the crystal ball of business! 🔮 It's where we gather " |
|
"data about the market to forecast trends, track competition, and make smarter investment decisions!" |
|
), |
|
"financials": ( |
|
"Financial analysis is like the heartbeat of a company 💓. It tells us if the company is healthy, " |
|
"sustainable, and ready to grow! 💰" |
|
), |
|
"investors": ( |
|
"Investors are like the superheroes of the business world 🦸♂️. They bring in the cash to fuel growth, " |
|
"while hoping for big returns on their investment!" |
|
) |
|
} |
|
return definitions.get(term.lower(), "Hmm, I don’t have a fun story for that term yet. Try another!") |
|
return None |
|
|
|
|
|
def get_groq_response(message, user_language): |
|
try: |
|
response = openai.ChatCompletion.create( |
|
model="llama-3.1-70b-versatile", |
|
messages=[ |
|
{ |
|
"role": "system", |
|
"content": ( |
|
f"You are a cheerful and energetic Private Market Analyst AI with a passion for explaining " |
|
f"complex market analysis with humor, analogies, and wit. Keep it fun, engaging, and informative! " |
|
f"Use your energy to keep the user excited and curious about market trends!" |
|
) |
|
}, |
|
{"role": "user", "content": message} |
|
] |
|
) |
|
return response.choices[0].message["content"] |
|
except Exception as e: |
|
return f"Oops, looks like something went wrong! Error: {str(e)}" |
|
|
|
|
|
def market_analysis_agent(user_input, history=[]): |
|
try: |
|
|
|
detected_language = detect(user_input) |
|
user_language = "Hindi" if detected_language == "hi" else "English" |
|
|
|
|
|
command_response = command_handler(user_input) |
|
if command_response: |
|
history.append((user_input, command_response)) |
|
return history, history |
|
|
|
|
|
if "company" in user_input.lower(): |
|
response = company_profile |
|
elif "financials" in user_input.lower(): |
|
response = financials |
|
elif "investors" in user_input.lower(): |
|
response = investors |
|
elif "products" in user_input.lower(): |
|
response = products_services |
|
elif "workforce" in user_input.lower(): |
|
response = workforce |
|
else: |
|
|
|
response = get_groq_response(user_input, user_language) |
|
|
|
|
|
cool_replies = [ |
|
"You're on fire! 🔥", |
|
"Boom! 💥 That’s a market insight right there!", |
|
"You’ve got this! 🚀", |
|
"Let's keep that momentum going! 💎", |
|
"That’s the power of market knowledge! 💪", |
|
"You’re crushing it! 🎯" |
|
] |
|
response = f"{response} {cool_replies[hash(user_input) % len(cool_replies)]}" |
|
|
|
|
|
history.append((user_input, response)) |
|
return history, history |
|
|
|
except Exception as e: |
|
return [(user_input, f"Oops, something went wrong: {str(e)}")], history |
|
|
|
|
|
chat_interface = gr.Interface( |
|
fn=market_analysis_agent, |
|
inputs=["text", "state"], |
|
outputs=["chatbot", "state"], |
|
live=False, |
|
title="Private Market AI Agent", |
|
description=( |
|
"Welcome to your cheerful and energetic Private Market Analyst! 🎉\n\n" |
|
"Ask me anything about company profiles, market trends, financials, investors, and more! 🌟" |
|
"I’ll break it down with jokes, stories, and humor to make market analysis a blast! 🚀" |
|
) |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
chat_interface.launch() |