Spaces:
Sleeping
Sleeping
| 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) |