File size: 1,383 Bytes
2dc5ecc
 
 
 
1818da7
 
a81c7d2
2dc5ecc
 
 
 
 
 
 
 
a81c7d2
2dc5ecc
 
a81c7d2
2dc5ecc
 
 
 
a81c7d2
 
 
 
 
 
 
 
2dc5ecc
 
 
 
 
a81c7d2
 
 
4ba9d84
2dc5ecc
 
 
 
405c501
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
import gradio as gr
from google import genai 
from smolagents import DuckDuckGoSearchTool

search_tool = DuckDuckGoSearchTool()

def search_and_answer(question: str , api_key: str) -> str: ## question string tipinde olmalı ve çıktısı da string olmalı , değişkenin doğru şekilde gönderilmesi ve çıktının istenilen formatta alınması sağlanabilir 
    result = search_tool(question)

    prompt = f''' {question} sorusunu arama sonuçlarına göre cevapla.
    Arama sonuçları : {result}
    Verdiğin yanıtın arama sonuçlarına dayalı olarak oluşturulmasına dikkat et.
    Kullanıcıya kısa bir yanıt sağla.
    ''' ##birden fazla satır olacaksa bu şekilde gösterebiliriz 

    client = genai.Client(api_key = api_key)
    response = client.models.generate_content(
        model = "gemini-2.0-flash" , 
        contents = [prompt] 
    )

    return response.text


api_key = gr.Textbox(
    placeholder = "Enter your Gemini API Key" , 
    label="🔑 API Key", 
    type = "password" , 
    interactive = True , 
    elem_id = "api-key-input"
)

demo = gr.Interface(
    fn = search_and_answer ,
    title = "Web Arama Destekli LLMs" ,  
    theme = gr.themes.Soft() ,
    inputs = [
        gr.Textbox(label="Soru") , 
        api_key 
    ] ,
    outputs = gr.Textbox(label="Cevap")
)

if __name__ == "__main__" : 
    demo.launch(show_error=True)