File size: 3,226 Bytes
ff0a8f3
 
 
 
 
f3c9c7f
 
 
 
dd767a0
f3c9c7f
ff0a8f3
 
 
f3c9c7f
ff0a8f3
 
 
 
f3c9c7f
ff0a8f3
 
 
 
 
 
 
 
 
 
f3c9c7f
 
 
ff0a8f3
f3c9c7f
d13b6c1
f3c9c7f
ff0a8f3
 
 
 
 
dd767a0
f3c9c7f
ff0a8f3
 
dd767a0
ff0a8f3
 
 
dd767a0
d13b6c1
ff0a8f3
 
 
d13b6c1
ff0a8f3
 
d13b6c1
dd767a0
d13b6c1
ff0a8f3
 
 
 
 
 
 
 
f3c9c7f
d13b6c1
f3c9c7f
 
 
d13b6c1
dd767a0
f3c9c7f
 
 
 
 
 
 
d13b6c1
f3c9c7f
 
 
 
 
 
d13b6c1
f3c9c7f
 
 
 
 
 
d13b6c1
f3c9c7f
 
 
 
d13b6c1
f3c9c7f
ff0a8f3
 
 
f3c9c7f
 
 
 
d13b6c1
 
f3c9c7f
 
 
 
ff0a8f3
 
 
 
f3c9c7f
 
ff0a8f3
 
f3c9c7f
 
 
 
ff0a8f3
 
 
 
f3c9c7f
 
ff0a8f3
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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(
        """
        <div id="logo">
            <span>G</span><span>o</span><span>o</span>
            <span>g</span><span>l</span><span>e</span>
        </div>
        """,
        elem_id="logo"
    )

    query_input = gr.Textbox(
        placeholder="Search anything...",
        lines=1,
        show_label=False,
        elem_classes="search-box"
    )

    search_button = gr.Button(
        "Search",
        elem_classes="search-btn"
    )

    answer_output = gr.Textbox(
        label="Search Result",
        lines=12,
        interactive=False,
        elem_classes="answer-box"
    )

    search_button.click(
        fn=google_style_search,
        inputs=query_input,
        outputs=answer_output
    )

demo.launch()