File size: 2,144 Bytes
964d3aa
84e65f7
964d3aa
84e65f7
 
964d3aa
0c7d341
13bcfb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c7d341
 
95d5b77
0c7d341
 
 
 
 
 
13bcfb8
0c7d341
 
 
 
 
 
 
 
 
 
 
 
 
 
964d3aa
 
4701079
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import requests

# Set your Hugging Face API key here
API_KEY = "your_huggingface_api_key"

def unified_function(operation, input_text):
    if operation == "Clean Diff":
        added_lines = []
        for line in input_text.split('\n'):
            if line.startswith('+') and not line.startswith('+++'):
                added_line = line[1:]  # Remove the '+' sign
                if sum(len(l) + 1 for l in added_lines) + len(added_line) <= 2000:
                    added_lines.append(added_line)
                else:
                    return "too long, try again"
                    break
        return '\n'.join(added_lines)

    elif operation == "Classify":
        API_URL = "https://api-inference.huggingface.co/models/davidgaofc/TechDebtClassifier"
        headers = {"Authorization": f"Bearer {API_KEY}"}
        data = {"inputs": input_text}

        response = requests.post(API_URL, headers=headers, json=data)
        result = response.json()
        return result

    elif operation == "Generate Label":
        API_URL = "https://api-inference.huggingface.co/models/davidgaofc/TechDebtLabeler"
        headers = {"Authorization": f"Bearer {API_KEY}"}
        data = {"inputs": input_text}

        response = requests.post(API_URL, headers=headers, json=data)
        result = response.json()
        return result

def huggingface_login(api_key):
    global API_KEY
    API_KEY = api_key
    return "success!"
# Create the Gradio interface
interface = gr.Interface(
    fn=unified_function,
    inputs=[
        gr.Dropdown(["Clean Diff", "Classify", "Generate Label"], label="Select Operation"),
        gr.Textbox(label="Input Text")
    ],
    outputs="text",
    title="Unified Interface for Multiple Functions",
    description="Select an operation from the dropdown and input text to see the result."
)

huggingface_interface = gr.Interface(
    fn=huggingface_login,
    inputs=gr.Textbox(lines=1, label="API Key"),
    outputs = "text"
)

tabbed_interface = gr.TabbedInterface([huggingface_interface, interface], ["Login", "Main"])

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