Spaces:
Running
Running
Commit ·
77bd823
1
Parent(s): f74d0ab
Completed the generate flowchart function besides the system prompt
Browse files
app.py
CHANGED
|
@@ -20,14 +20,13 @@ Model:
|
|
| 20 |
https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct-GGUF
|
| 21 |
|
| 22 |
To do
|
| 23 |
-
- need to create the basic gradio looks
|
| 24 |
-
- need to use llama.cpp
|
| 25 |
-
- code and pipeline
|
| 26 |
|
| 27 |
"""
|
| 28 |
from huggingface_hub import hf_hub_download
|
| 29 |
from llama_cpp import Llama
|
| 30 |
import gradio as gr
|
|
|
|
| 31 |
|
| 32 |
# ----- Get Model ----- #
|
| 33 |
# Download Q4_K_M GGUF file from the repo
|
|
@@ -45,5 +44,30 @@ llm = Llama(
|
|
| 45 |
|
| 46 |
# ----- Generation function ----- #
|
| 47 |
def generate_flowchart(src_code: str):
|
| 48 |
-
#
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct-GGUF
|
| 21 |
|
| 22 |
To do
|
| 23 |
+
- need to create the basic gradio looks & pipeline
|
|
|
|
|
|
|
| 24 |
|
| 25 |
"""
|
| 26 |
from huggingface_hub import hf_hub_download
|
| 27 |
from llama_cpp import Llama
|
| 28 |
import gradio as gr
|
| 29 |
+
from typing import Any, cast # to resolve PyLance freaking out over llama-cpp-python in the generate_flowchart function
|
| 30 |
|
| 31 |
# ----- Get Model ----- #
|
| 32 |
# Download Q4_K_M GGUF file from the repo
|
|
|
|
| 44 |
|
| 45 |
# ----- Generation function ----- #
|
| 46 |
def generate_flowchart(src_code: str):
|
| 47 |
+
# check if src_code is empty
|
| 48 |
+
if not src_code.strip(): return ""
|
| 49 |
+
|
| 50 |
+
system_prompt = (
|
| 51 |
+
"..."
|
| 52 |
+
"..."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Casting else PyLance gets mad
|
| 56 |
+
response = cast(Any, llm.create_chat_completion(
|
| 57 |
+
messages=[
|
| 58 |
+
{"role": "system", "content": system_prompt},
|
| 59 |
+
{"role": "user", "content": src_code}
|
| 60 |
+
],
|
| 61 |
+
temperature=0.1, # Keep it quite deterministic for now
|
| 62 |
+
max_tokens=1024,
|
| 63 |
+
stream=False
|
| 64 |
+
))
|
| 65 |
+
|
| 66 |
+
content = response["choices"][0]["message"]["content"]
|
| 67 |
+
|
| 68 |
+
# Fallback to fix the .strip() on None error
|
| 69 |
+
mermaid_raw = (content or "").strip()
|
| 70 |
+
|
| 71 |
+
return mermaid_raw
|
| 72 |
+
|
| 73 |
+
# ----- Gradio Interface (Basic, Not Custom) ----- #
|