Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,88 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from
|
4 |
-
|
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 |
-
return
|
32 |
-
|
33 |
-
messages = [{"role": "system", "content": system_message}]
|
34 |
-
|
35 |
-
for val in history:
|
36 |
-
if val[0]:
|
37 |
-
messages.append({"role": "user", "content": val[0]})
|
38 |
-
if val[1]:
|
39 |
-
messages.append({"role": "assistant", "content": val[1]})
|
40 |
-
|
41 |
-
messages.append({"role": "user", "content": message})
|
42 |
-
|
43 |
-
response = ""
|
44 |
-
|
45 |
-
for message in client.chat_completion(
|
46 |
-
messages,
|
47 |
-
max_tokens=max_tokens,
|
48 |
-
stream=True,
|
49 |
-
temperature=temperature,
|
50 |
-
top_p=top_p,
|
51 |
-
):
|
52 |
-
token = message.choices[0].delta.content
|
53 |
-
response += token
|
54 |
-
yield response
|
55 |
-
|
56 |
-
|
57 |
-
# Koyu tema tanımlama
|
58 |
-
theme=gr.themes.Soft(
|
59 |
-
primary_hue="emerald",
|
60 |
-
secondary_hue="emerald",
|
61 |
-
neutral_hue="gray",
|
62 |
-
font=[
|
63 |
-
gr.themes.GoogleFont("Exo"),
|
64 |
-
"ui-sans-serif",
|
65 |
-
"system-ui",
|
66 |
-
"sans-serif"
|
67 |
-
]).set(
|
68 |
-
body_background_fill_dark="#010409",
|
69 |
-
block_background_fill_dark="#010409",
|
70 |
-
block_border_width="1px",
|
71 |
-
block_title_background_fill_dark="#1e1c26",
|
72 |
-
input_background_fill_dark="#161b22",
|
73 |
-
button_secondary_background_fill_dark="#21262d",
|
74 |
-
border_color_accent_dark="#2f353c",
|
75 |
-
border_color_primary_dark="#2f353c",
|
76 |
-
background_fill_secondary_dark="#010409",
|
77 |
-
color_accent_soft_dark="transparent",
|
78 |
-
code_background_fill_dark="#0d1117",
|
79 |
-
)
|
80 |
-
|
81 |
-
|
82 |
-
# Demo başlatılıyor
|
83 |
-
demo = gr.ChatInterface(
|
84 |
-
respond,
|
85 |
-
)
|
86 |
-
|
87 |
-
if __name__ == "__main__":
|
88 |
-
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
|
4 |
+
|
5 |
+
# AlpDroid promptunu GitHub'dan çek
|
6 |
+
alp_prompt_url = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
|
7 |
+
alp_prompt = requests.get(alp_prompt_url).text.strip()
|
8 |
+
|
9 |
+
# Model ve tokenizer'ı yükle
|
10 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
|
13 |
+
|
14 |
+
# Pipeline oluştur
|
15 |
+
pipeline = TextGenerationPipeline(model=model, tokenizer=tokenizer)
|
16 |
+
|
17 |
+
# Gradio fonksiyonu
|
18 |
+
def chat(prompt):
|
19 |
+
full_prompt = f"{alp_prompt}\n\nKullanıcı: {prompt}\nAlpDroid:"
|
20 |
+
result = pipeline(full_prompt, max_new_tokens=200, temperature=0.8, top_p=0.9)[0]["generated_text"]
|
21 |
+
# Sadece cevabı almak için promptu ayıkla
|
22 |
+
response = result.split("AlpDroid:")[-1].strip()
|
23 |
+
return response
|
24 |
+
|
25 |
+
# Gradio arayüzü
|
26 |
+
gr.Interface(fn=chat,
|
27 |
+
inputs=gr.Textbox(label="Mesajını yaz, AlpDroid cevaplasın"),
|
28 |
+
outputs=gr.Textbox(label="AlpDroid"),
|
29 |
+
title="🧠 AlpDroid (Mistral 7B)",
|
30 |
+
description="Alper'in vizyonuyla hazırlanmış AlpDroid, şimdi seninle...").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|