alperall commited on
Commit
35bdabf
·
verified ·
1 Parent(s): 7f2c303

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -83
app.py CHANGED
@@ -1,88 +1,20 @@
1
  import gradio as gr
2
- import requests
3
- from huggingface_hub import InferenceClient
4
 
5
- client = InferenceClient("Qwen/Qwen3-235B-A22B")
 
 
 
6
 
7
- # Sabit GitHub raw URL'si
8
- GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
9
 
 
 
 
 
10
 
11
- def fetch_system_message():
12
- """Fetch system message from a GitHub raw link."""
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
-
21
- def respond(message, history):
22
- # Sabit parametreler
23
- max_tokens = 512
24
- temperature = 0.7
25
- top_p = 0.95
26
-
27
- # Fetch the system message from GitHub
28
- system_message = fetch_system_message()
29
- if system_message.startswith("Error"):
30
- yield system_message
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
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
 
3
 
4
+ # Model ve Tokenizer yükleniyor
5
+ model_name = "mistralai/Mistral-7B-Instruct-v0.1"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto")
8
 
9
+ # Pipeline oluşturuluyor
10
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=200)
11
 
12
+ # Gradio arayüzü
13
+ def chat_with_ai(prompt):
14
+ result = pipe(prompt)[0]['generated_text']
15
+ return result
16
 
17
+ gr.Interface(fn=chat_with_ai,
18
+ inputs=gr.Textbox(label="Patron Soruyu Sor"),
19
+ outputs=gr.Textbox(label="AlpDroid Cevaplıyor"),
20
+ title="AlpDroid 7B - Grok Tarzı Açık AI").launch()