Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 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.
|
|
@@ -15,20 +13,31 @@ def search_and_answer(question:str) -> str: ## question string tipinde olmalı v
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn = search_and_answer ,
|
| 29 |
title = "Web Arama Destekli LLMs" ,
|
| 30 |
theme = gr.themes.Soft() ,
|
| 31 |
-
inputs =
|
|
|
|
|
|
|
|
|
|
| 32 |
outputs = gr.Textbox(label="Cevap")
|
| 33 |
)
|
| 34 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
|
|
|
| 3 |
from smolagents import DuckDuckGoSearchTool
|
| 4 |
|
| 5 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 6 |
|
| 7 |
+
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
|
| 8 |
result = search_tool(question)
|
| 9 |
|
| 10 |
prompt = f''' {question} sorusunu arama sonuçlarına göre cevapla.
|
|
|
|
| 13 |
Kullanıcıya kısa bir yanıt sağla.
|
| 14 |
''' ##birden fazla satır olacaksa bu şekilde gösterebiliriz
|
| 15 |
|
| 16 |
+
client = genai.Client(api_key = api_key)
|
| 17 |
response = client.models.generate_content(
|
| 18 |
model = "gemini-2.0-flash" ,
|
| 19 |
+
contents = [prompt]
|
| 20 |
)
|
| 21 |
|
| 22 |
return response.text
|
| 23 |
|
| 24 |
+
|
| 25 |
+
api_key = gr.Textbox(
|
| 26 |
+
placeholder = "Enter your Gemini API Key" ,
|
| 27 |
+
label="🔑 API Key",
|
| 28 |
+
type = "password" ,
|
| 29 |
+
interactive = True ,
|
| 30 |
+
elem_id = "api-key-input"
|
| 31 |
+
)
|
| 32 |
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn = search_and_answer ,
|
| 35 |
title = "Web Arama Destekli LLMs" ,
|
| 36 |
theme = gr.themes.Soft() ,
|
| 37 |
+
inputs = [
|
| 38 |
+
gr.Textbox(label="Soru") ,
|
| 39 |
+
api_key
|
| 40 |
+
]
|
| 41 |
outputs = gr.Textbox(label="Cevap")
|
| 42 |
)
|
| 43 |
|