Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
from duckduckgo_search import DDGS
|
| 5 |
+
|
| 6 |
+
# Modeli yükle (Hugging Face sunucularında çalışacak)
|
| 7 |
+
model_id = "unsloth/gemma-2-9b-it-bnb-4bit"
|
| 8 |
+
pipe = pipeline("text-generation", model=model_id, device_map="auto", model_kwargs={"torch_dtype": torch.bfloat16})
|
| 9 |
+
|
| 10 |
+
def internetten_ara(soru):
|
| 11 |
+
with DDGS() as ddgs:
|
| 12 |
+
results = [r for r in ddgs.text(soru, max_results=3)]
|
| 13 |
+
return "\n".join([r['body'] for r in results])
|
| 14 |
+
|
| 15 |
+
def turkbot_cevap(mesaj, history):
|
| 16 |
+
bilgi = internetten_ara(mesaj)
|
| 17 |
+
prompt = f"<start_of_turn>user\nBilgi: {bilgi}\nSoru: {mesaj}<end_of_turn>\n<start_of_turn>model\n"
|
| 18 |
+
|
| 19 |
+
cevap = pipe(prompt, max_new_tokens=300)[0]['generated_text']
|
| 20 |
+
return cevap.split("<start_of_turn>model\n")[-1]
|
| 21 |
+
|
| 22 |
+
# Harika bir kullanıcı arayüzü
|
| 23 |
+
demo = gr.ChatInterface(fn=turkbot_cevap, title="TURKBOT v1.0", description="İnternete bağlı, canlı Turkbot!")
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|