Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
# ම
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|