borakol commited on
Commit
2dc5ecc
·
verified ·
1 Parent(s): b444ffc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -36
app.py CHANGED
@@ -1,37 +1,36 @@
1
- import os
2
- import gradio as gr
3
- from google import genai
4
- from api_read import GEMINI_API_KEY
5
- from smolagents import DuckDuckGoSearchTool
6
-
7
- search_tool = DuckDuckGoSearchTool()
8
- client = genai.Client(api_key=GEMINI_API_KEY)
9
-
10
- def search_and_answer(question: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
11
- result = search_tool(question)
12
-
13
- prompt = f''' {question} sorusunu arama sonuçlarına göre cevapla.
14
- Arama sonuçları : {result}
15
- Verdiğin yanıtın arama sonuçlarına dayalı olarak oluşturulmasına dikkat et.
16
- Kullanıcıya kısa bir yanıt sağla.
17
- ''' ##birden fazla satır olacaksa bu şekilde gösterebiliriz
18
-
19
- response = client.models.generate_content(
20
- model = "gemini-2.0-flash" ,
21
- contents = prompt
22
- )
23
-
24
- return response.text
25
-
26
- print(search_and_answer("24 Şubat 2025 tarihli GS-FB maçı skoru?"))
27
-
28
- demo = gr.Interface(
29
- fn = search_and_answer ,
30
- title = "Web Arama Destekli LLMs" ,
31
- theme = gr.themes.Soft() ,
32
- inputs = gr.Textbox(label="Soru") ,
33
- outputs = gr.Textbox(label="Cevap")
34
- )
35
-
36
- if __name__ == "__main__" :
37
  demo.launch(show_error=True)
 
1
+ import gradio as gr
2
+ from google import genai
3
+ from api_read import GEMINI_API_KEY
4
+ from smolagents import DuckDuckGoSearchTool
5
+
6
+ search_tool = DuckDuckGoSearchTool()
7
+ client = genai.Client(api_key=GEMINI_API_KEY)
8
+
9
+ def search_and_answer(question: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
10
+ result = search_tool(question)
11
+
12
+ prompt = f''' {question} sorusunu arama sonuçlarına göre cevapla.
13
+ Arama sonuçları : {result}
14
+ Verdiğin yanıtın arama sonuçlarına dayalı olarak oluşturulmasına dikkat et.
15
+ Kullanıcıya kısa bir yanıt sağla.
16
+ ''' ##birden fazla satır olacaksa bu şekilde gösterebiliriz
17
+
18
+ response = client.models.generate_content(
19
+ model = "gemini-2.0-flash" ,
20
+ contents = prompt
21
+ )
22
+
23
+ return response.text
24
+
25
+ print(search_and_answer("24 Şubat 2025 tarihli GS-FB maçı skoru?"))
26
+
27
+ demo = gr.Interface(
28
+ fn = search_and_answer ,
29
+ title = "Web Arama Destekli LLMs" ,
30
+ theme = gr.themes.Soft() ,
31
+ inputs = gr.Textbox(label="Soru") ,
32
+ outputs = gr.Textbox(label="Cevap")
33
+ )
34
+
35
+ if __name__ == "__main__" :
 
36
  demo.launch(show_error=True)