Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,35 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from llama_cpp import Llama
|
| 3 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 4 |
|
| 5 |
try:
|
| 6 |
-
|
|
|
|
| 7 |
model_path = hf_hub_download(
|
| 8 |
repo_id='Arabic250/gemma-4-gguf-export',
|
| 9 |
filename='gemma-4-medical.gguf'
|
| 10 |
)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
prompt =
|
| 18 |
-
|
| 19 |
-
prompt += f"USER: {user_msg}\nASSISTANT: {bot_msg}\n"
|
| 20 |
-
|
| 21 |
-
prompt += f"USER: {message}\nASSISTANT: "
|
| 22 |
-
|
| 23 |
-
# echo=False تمنع النموذج من تكرار السؤال في الإجابة
|
| 24 |
-
output = llm(prompt, max_tokens=512, stop=['USER:'], echo=False)
|
| 25 |
-
return output['choices'][0]['text']
|
| 26 |
-
|
| 27 |
-
demo = gr.ChatInterface(fn=chat, title='Gemma 4 Medical')
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
with gr.Blocks() as demo:
|
| 31 |
-
gr.Markdown(f
|
| 32 |
|
| 33 |
if __name__ == '__main__':
|
| 34 |
-
|
| 35 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from llama_cpp import Llama
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
try:
|
| 7 |
+
# تحميل ملف GGUF من المستودع الخارجي لتجاوز حد المساحة (1GB)
|
| 8 |
+
print("--- Downloading Gemma 4 GGUF Model ---")
|
| 9 |
model_path = hf_hub_download(
|
| 10 |
repo_id='Arabic250/gemma-4-gguf-export',
|
| 11 |
filename='gemma-4-medical.gguf'
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# تهيئة النموذج
|
| 15 |
+
print("--- Initializing Engine ---")
|
| 16 |
+
llm = Llama(model_path=model_path, n_ctx=1024, n_threads=2)
|
| 17 |
|
| 18 |
+
def predict(message, history):
|
| 19 |
+
prompt = f"USER: {message}\nASSISTANT: "
|
| 20 |
+
response = llm(prompt, max_tokens=512, stop=['USER:'], echo=False)
|
| 21 |
+
return response['choices'][0]['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
demo = gr.ChatInterface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
title='⚡ Gemma 4 Medical - Docker Edition',
|
| 26 |
+
description='واجهة دردشة طبية تعمل بنظام Docker المستقر.'
|
| 27 |
+
)
|
| 28 |
except Exception as e:
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown(f"# ❌ Error: {e}")
|
| 31 |
|
| 32 |
if __name__ == '__main__':
|
| 33 |
+
demo.launch(server_name='0.0.0.0', server_port=7860)
|
|
|