Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +37 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
google-genai
|
| 2 |
+
os
|
| 3 |
+
smolagents
|