davidgaofc commited on
Commit
13bcfb8
1 Parent(s): 0c7d341

maybe works

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -5,15 +5,35 @@ import requests
5
  API_KEY = "your_huggingface_api_key"
6
 
7
  def unified_function(operation, input_text):
8
- if operation == "Text Generation":
9
- return "gen" + input_text
10
-
11
- elif operation == "Sentiment Analysis":
12
-
13
- return "sent" + input_text
14
-
15
- elif operation == "Echo Text":
16
- return "echo" + input_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def huggingface_login(api_key):
19
  API_KEY = api_key
@@ -22,7 +42,7 @@ def huggingface_login(api_key):
22
  interface = gr.Interface(
23
  fn=unified_function,
24
  inputs=[
25
- gr.Dropdown(["Text Generation", "Sentiment Analysis", "Echo Text"], label="Select Operation"),
26
  gr.Textbox(label="Input Text")
27
  ],
28
  outputs="text",
 
5
  API_KEY = "your_huggingface_api_key"
6
 
7
  def unified_function(operation, input_text):
8
+ if operation == "Clean Diff":
9
+ added_lines = []
10
+ for line in input_text.split('\n'):
11
+ if line.startswith('+') and not line.startswith('+++'):
12
+ added_line = line[1:] # Remove the '+' sign
13
+ if sum(len(l) + 1 for l in added_lines) + len(added_line) <= 2000:
14
+ added_lines.append(added_line)
15
+ else:
16
+ return "too long, try again"
17
+ break
18
+ return '\n'.join(added_lines)
19
+
20
+ elif operation == "Classify":
21
+ API_URL = "https://api-inference.huggingface.co/models/davidgaofc/TechDebtClassifier"
22
+ headers = {"Authorization": f"Bearer {API_KEY}"}
23
+ data = {"inputs": input_text}
24
+
25
+ response = requests.post(API_URL, headers=headers, json=data)
26
+ result = response.json()
27
+ return result
28
+
29
+ elif operation == "Generate Label":
30
+ API_URL = "https://api-inference.huggingface.co/models/davidgaofc/TechDebtLabeler"
31
+ headers = {"Authorization": f"Bearer {API_KEY}"}
32
+ data = {"inputs": input_text}
33
+
34
+ response = requests.post(API_URL, headers=headers, json=data)
35
+ result = response.json()
36
+ return result
37
 
38
  def huggingface_login(api_key):
39
  API_KEY = api_key
 
42
  interface = gr.Interface(
43
  fn=unified_function,
44
  inputs=[
45
+ gr.Dropdown(["Clean Diff", "Classify", "Generate Label"], label="Select Operation"),
46
  gr.Textbox(label="Input Text")
47
  ],
48
  outputs="text",