Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,36 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
-
from
|
| 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 |
-
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)
|