import os import gradio as gr from langchain_groq import ChatGroq from langchain_tavily import TavilySearch GROQ_API_KEY = os.getenv("GROQ_API_KEY") TAVILY_API_KEY = os.getenv("TAVILY_API_KEY") if not GROQ_API_KEY or not TAVILY_API_KEY: raise ValueError("Set GROQ_API_KEY and TAVILY_API_KEY in Hugging Face Secrets") llm = ChatGroq( model_name="openai/gpt-oss-120b", temperature=0, groq_api_key=GROQ_API_KEY ) search = TavilySearch( max_results=5, tavily_api_key=TAVILY_API_KEY ) def google_style_search(query): if not query.strip(): return "Please enter a search query." res = search.invoke(query) context = "\n".join([r["content"] for r in res.get("results", [])]) prompt = f""" Using the following web search information: {context} Question: {query} Answer clearly and concisely like Google Search: """ response = llm.invoke(prompt) return response.content.strip() google_css = """ @import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap'); body { background-color: #ffffff; font-family: 'Google Sans', Arial, sans-serif; } .gradio-container { max-width: 900px !important; margin-top: 40px; } #logo { font-size: 96px; font-weight: 700; text-align: center; margin-bottom: 45px; letter-spacing: -2px; line-height: 1.1; } #logo span:nth-child(1) { color: #4285F4; } #logo span:nth-child(2) { color: #DB4437; } #logo span:nth-child(3) { color: #F4B400; } #logo span:nth-child(4) { color: #4285F4; } #logo span:nth-child(5) { color: #0F9D58; } #logo span:nth-child(6) { color: #DB4437; } /* Search box */ .search-box textarea { border-radius: 24px !important; border: 1px solid #dfe1e5 !important; padding: 16px 22px !important; font-size: 17px !important; } .search-box textarea:focus { box-shadow: 0 1px 6px rgba(32,33,36,.28); border-color: transparent !important; } /* Button */ .search-btn button { border-radius: 6px !important; background-color: #f8f9fa !important; color: #202124 !important; border: 1px solid #f8f9fa !important; font-weight: 500; padding: 10px 18px; } .search-btn button:hover { border: 1px solid #dadce0 !important; } /* Answer box */ .answer-box textarea { border-radius: 12px !important; background: #f8f9fa !important; font-size: 15px !important; line-height: 1.7; } """ with gr.Blocks(css=google_css) as demo: gr.Markdown( """