minzo456 commited on
Commit
5f0e231
·
verified ·
1 Parent(s): d13f15f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -1,13 +1,30 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # මොඩල් එක දී Load වෙවා
5
- pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct")
6
 
7
- def predict(message, history):
8
- # AI පිළිතුර උත්පාදනය කිරීම
9
- response = pipe(message, max_new_tokens=512)[0]['generated_text']
10
- return response
 
 
11
 
12
- # API එකක් ලෙස මෙය විවෘත කිරීම
13
- gr.ChatInterface(predict).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ # මෙහි ඔබේ Token එක ලි්ම ඇතුළත් කර්න
5
+ client = InferenceClient("Qwen/Qwen2.5-1.5B-Instruct", token="HF_TOKEN")
6
 
7
+ def respond(message, history):
8
+ messages = [{"role": "system", "content": "You are MINZO AI, a strategic assistant for Commander MINZO-PRIME."}]
9
+
10
+ for val in history:
11
+ if val[0]: messages.append({"role": "user", "content": val[0]})
12
+ if val[1]: messages.append({"role": "assistant", "content": val[1]})
13
 
14
+ messages.append({"role": "user", "content": message})
15
+
16
+ response = ""
17
+ for message in client.chat_completion(
18
+ messages,
19
+ max_tokens=1024,
20
+ stream=True,
21
+ temperature=0.7,
22
+ ):
23
+ token = message.choices[0].delta.content
24
+ response += token
25
+ yield response
26
+
27
+ demo = gr.ChatInterface(respond)
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch()