Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from huggingface_hub import InferenceClient
|
4 |
+
|
5 |
+
# HuggingFace modeli
|
6 |
+
client = InferenceClient("MiniMaxAI/MiniMax-VL-01")
|
7 |
+
|
8 |
+
# GitHub'dan sistem mesajı çekeceğimiz bağlantı
|
9 |
+
GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
|
10 |
+
|
11 |
+
# Sistem mesajını GitHub'dan çeken fonksiyon
|
12 |
+
def fetch_system_message():
|
13 |
+
try:
|
14 |
+
response = requests.get(GITHUB_RAW_URL)
|
15 |
+
response.raise_for_status()
|
16 |
+
return response.text.strip()
|
17 |
+
except requests.exceptions.RequestException as e:
|
18 |
+
return f"Error fetching system message: {str(e)}"
|
19 |
+
|
20 |
+
# Kullanıcının yazdığı mesaja yanıt oluşturan fonksiyon
|
21 |
+
def respond(message, history):
|
22 |
+
max_tokens = 512
|
23 |
+
temperature = 0.7
|
24 |
+
top_p = 0.95
|
25 |
+
|
26 |
+
# Sistem mesajı çekiliyor
|
27 |
+
system_message = fetch_system_message()
|
28 |
+
if system_message.startswith("Error"):
|
29 |
+
yield system_message
|
30 |
+
return
|
31 |
+
|
32 |
+
messages = [{"role": "system", "content": system_message}]
|
33 |
+
|
34 |
+
for val in history:
|
35 |
+
if val[0]:
|
36 |
+
messages.append({"role": "user", "content": val[0]})
|
37 |
+
if val[1]:
|
38 |
+
messages.append({"role": "assistant", "content": val[1]})
|
39 |
+
|
40 |
+
messages.append({"role": "user", "content": message})
|
41 |
+
|
42 |
+
response = ""
|
43 |
+
|
44 |
+
for message in client.chat_completion(
|
45 |
+
messages,
|
46 |
+
max_tokens=max_tokens,
|
47 |
+
stream=True,
|
48 |
+
temperature=temperature,
|
49 |
+
top_p=top_p,
|
50 |
+
):
|
51 |
+
token = message.choices[0].delta.content
|
52 |
+
response += token
|
53 |
+
yield response
|
54 |
+
|
55 |
+
# Tema tanımı (koyu renk ve özel yazı tipi ile)
|
56 |
+
theme = gr.themes.Soft(
|
57 |
+
primary_hue="emerald",
|
58 |
+
secondary_hue="emerald",
|
59 |
+
neutral_hue="gray",
|
60 |
+
font=[
|
61 |
+
gr.themes.GoogleFont("Exo"),
|
62 |
+
"ui-sans-serif",
|
63 |
+
"system-ui",
|
64 |
+
"sans-serif"
|
65 |
+
]
|
66 |
+
).set(
|
67 |
+
body_background_fill_dark="#010409",
|
68 |
+
block_background_fill_dark="#010409",
|
69 |
+
block_border_width="1px",
|
70 |
+
block_title_background_fill_dark="#1e1c26",
|
71 |
+
input_background_fill_dark="#161b22",
|
72 |
+
button_secondary_background_fill_dark="#21262d",
|
73 |
+
border_color_accent_dark="#2f353c",
|
74 |
+
border_color_primary_dark="#2f353c",
|
75 |
+
background_fill_secondary_dark="#010409",
|
76 |
+
color_accent_soft_dark="transparent",
|
77 |
+
code_background_fill_dark="#0d1117",
|
78 |
+
)
|
79 |
+
|
80 |
+
# Gradio arayüzü
|
81 |
+
demo = gr.ChatInterface(
|
82 |
+
respond,
|
83 |
+
textbox=gr.Textbox(placeholder="Ask me anything. You can also drop in images and .mp4 videos."),
|
84 |
+
theme=theme,
|
85 |
+
)
|
86 |
+
|
87 |
+
# Uygulama çalıştırılıyor
|
88 |
+
if __name__ == "__main__":
|
89 |
+
demo.launch(share=True)
|