abdulmeLINK commited on
Commit
56d8167
·
1 Parent(s): c00d31d

app.py upload

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+
5
+
6
+ # ENV vars
7
+ API_URL = os.environ["API_URL"]
8
+ HF_TOKEN = os.environ["HF_TOKEN"]
9
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
10
+
11
+ langs = ['C', 'C++', 'Java', 'Golang', 'Rust',
12
+ 'Javascript', 'PHP', 'Kotlin', 'HTML', 'Python', 'Bash', 'Ruby']
13
+
14
+ jsn_trail = {"parameters":
15
+ {
16
+ "top_p": 0.9,
17
+ "max_new_tokens": 64,
18
+ "return_full_text": True,
19
+ "do_sample": True,
20
+ },
21
+ "options":
22
+ {"use_cache": True,
23
+ "wait_for_model": True,
24
+ }, }
25
+
26
+
27
+ def post(jsn):
28
+ response = requests.post(API_URL, headers=headers, json=jsn)
29
+ return response.json()[0]["generated_text"]
30
+
31
+
32
+ def divider(char='=', length=20):
33
+ return char*length + '\n'
34
+
35
+
36
+ def get_solution(lang, error):
37
+ jsn = {"inputs": "**Programming Language**:\n" + lang + divider +
38
+ '**Error**:\n'+error+divider+"**Solution**:\n", **jsn_trail}
39
+ return post(jsn)
40
+
41
+
42
+ def feedback(opt):
43
+ return post({"inputs": opt, **jsn_trail})
44
+
45
+
46
+ demo = gr.Blocks()
47
+
48
+ with demo:
49
+ gr.Markdown(
50
+ "<h1><center>Paste your error to see solution</center></h1>")
51
+ with gr.Row():
52
+ dropdown = gr.Dropdown(value="Python",
53
+ choices=langs, label="Choose the language")
54
+ # with gr.Column:
55
+ error = gr.Textbox(label="Write the error output",
56
+ value="Traceback (most recent call last):\nFile " < stdin > ", line 1, in <module>\nNameError: name 'variable' is not defined", lines=6)
57
+
58
+ with gr.Row():
59
+ generated_txt = gr.Textbox(lines=5, interactive=False, label="Output")
60
+
61
+ btn = gr.Button("Solve")
62
+ btn.click(get_solution, inputs=[dropdown,
63
+ error], outputs=generated_txt)
64
+ feeedback_btn = gr.Button("Feedback")
65
+ feeedback_btn.click(
66
+ feedback, inputs=[generated_txt], outputs=generated_txt)
67
+ with gr.Row():
68
+ gr.Markdown(
69
+ "![visitor badge](https://visitor-badge.glitch.me/badge?page_id=abdulmeLINK.debugger-bloom)")
70
+
71
+ demo.launch(enable_queue=True, debug=True)