File size: 1,263 Bytes
07a91a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Gradio app for Hugging Face Spaces deployment."""

from __future__ import annotations

import json

import gradio as gr

from src.pipeline import CodingLLMPipeline

pipeline = CodingLLMPipeline()


def generate(instruction: str, user_input: str):
    try:
        result = pipeline.run(instruction, user_input)
        return json.dumps(result, indent=2)
    except Exception as exc:
        return json.dumps(
            {
                "code": "",
                "explanation": f"Generation failed: {exc}",
                "confidence": 0.0,
                "important_tokens": [],
                "relevancy_score": 0.0,
                "hallucination": True,
                "latency_ms": 0,
            },
            indent=2,
        )


demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label="Instruction", placeholder="Explain, generate or debug code..."),
        gr.Textbox(label="Input", lines=12, placeholder="Paste code or context"),
    ],
    outputs=gr.Code(label="JSON Output", language="json"),
    title="Advanced Coding LLM",
    description="Fast coding assistant with confidence, relevancy, and hallucination checks.",
)

if __name__ == "__main__":
    demo.launch()