Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# 🔹 Stáhneme model, pokud není dostupný
|
| 7 |
+
MODEL_NAME = "TheBloke/Mistral-7B-Instruct-GGUF"
|
| 8 |
+
MODEL_FILE = "Mistral-7B-Instruct-Q4_K_M.gguf"
|
| 9 |
+
MODEL_PATH = f"./{MODEL_FILE}"
|
| 10 |
+
|
| 11 |
+
if not os.path.exists(MODEL_PATH):
|
| 12 |
+
from huggingface_hub import hf_hub_download
|
| 13 |
+
MODEL_PATH = hf_hub_download(repo_id=MODEL_NAME, filename=MODEL_FILE)
|
| 14 |
+
|
| 15 |
+
# 🔹 Načteme model do RAM
|
| 16 |
+
llm = Llama(model_path=MODEL_PATH, n_ctx=1024, n_threads=8, verbose=False)
|
| 17 |
+
|
| 18 |
+
def chat(user_input):
|
| 19 |
+
""" 🗣️ AI odpovídá na dotazy """
|
| 20 |
+
response = llm(user_input, max_tokens=256, temperature=0.7)
|
| 21 |
+
return response["choices"][0]["text"]
|
| 22 |
+
|
| 23 |
+
# 🔹 Vytvoříme jednoduché UI
|
| 24 |
+
interface = gr.Interface(fn=chat, inputs="text", outputs="text", title="🤖 Česká AI zdarma!")
|
| 25 |
+
|
| 26 |
+
# 🔹 Spustíme server
|
| 27 |
+
interface.launch()
|