Create app.py
#8
by
sky-meilin
- opened
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# 🔥 Program Synthesis Modell
|
| 5 |
+
synthesizer = pipeline("text-generation", model="microsoft/CodeGPT-small-py")
|
| 6 |
+
|
| 7 |
+
# 🔹 Gravatar
|
| 8 |
+
GRAVATAR_URL = "https://www.gravatar.com/avatar/7e6d02f7b39c0f35f7eae2f404a7d0b1?s=200"
|
| 9 |
+
GRAVATAR_LINK = "https://gravatar.com/skymeilin"
|
| 10 |
+
|
| 11 |
+
# 🔹 Finger Funktionen
|
| 12 |
+
def code_analysis(prompt):
|
| 13 |
+
return synthesizer(f"# Analysiere den Code:\n{prompt}\n# Analyse:", max_length=300)[0]['generated_text']
|
| 14 |
+
|
| 15 |
+
def code_optimization(prompt):
|
| 16 |
+
return synthesizer(f"# Optimiere den folgenden Code:\n{prompt}\n# Optimierter Code:", max_length=300)[0]['generated_text']
|
| 17 |
+
|
| 18 |
+
def code_comment(prompt):
|
| 19 |
+
return synthesizer(f"# Kommentiere den Code:\n{prompt}\n# Kommentar:", max_length=300)[0]['generated_text']
|
| 20 |
+
|
| 21 |
+
def code_multilang(prompt):
|
| 22 |
+
return synthesizer(f"# Übersetze oder generiere in gewünschter Sprache:\n{prompt}\n# Code:", max_length=300)[0]['generated_text']
|
| 23 |
+
|
| 24 |
+
def code_debug(prompt):
|
| 25 |
+
return synthesizer(f"# Finde Bugs und Vorschläge:\n{prompt}\n# Debug:", max_length=300)[0]['generated_text']
|
| 26 |
+
|
| 27 |
+
def code_test(prompt):
|
| 28 |
+
return synthesizer(f"# Generiere Testfälle für:\n{prompt}\n# Tests:", max_length=300)[0]['generated_text']
|
| 29 |
+
|
| 30 |
+
def code_refactor(prompt):
|
| 31 |
+
return synthesizer(f"# Refactore den Code nach Best Practices:\n{prompt}\n# Refactored Code:", max_length=300)[0]['generated_text']
|
| 32 |
+
|
| 33 |
+
def code_doc(prompt):
|
| 34 |
+
return synthesizer(f"# Dokumentiere den Code:\n{prompt}\n# Dokumentation:", max_length=300)[0]['generated_text']
|
| 35 |
+
|
| 36 |
+
def code_boilerplate(prompt):
|
| 37 |
+
return synthesizer(f"# Generiere Boilerplate / Deployment Code:\n{prompt}\n# Code:", max_length=300)[0]['generated_text']
|
| 38 |
+
|
| 39 |
+
def code_custom(prompt):
|
| 40 |
+
return synthesizer(f"# Eigene Conversational Anfrage:\n{prompt}\n# Antwort:", max_length=300)[0]['generated_text']
|
| 41 |
+
|
| 42 |
+
# Mapping Finger-Buttons
|
| 43 |
+
fingers = {
|
| 44 |
+
"Analyse": code_analysis,
|
| 45 |
+
"Optimierung": code_optimization,
|
| 46 |
+
"Kommentierung": code_comment,
|
| 47 |
+
"Mehrsprachig": code_multilang,
|
| 48 |
+
"Debugging": code_debug,
|
| 49 |
+
"Testfälle": code_test,
|
| 50 |
+
"Refactoring": code_refactor,
|
| 51 |
+
"Dokumentation": code_doc,
|
| 52 |
+
"Boilerplate": code_boilerplate,
|
| 53 |
+
"Conversational": code_custom
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
# Gradio UI
|
| 57 |
+
with gr.Blocks() as app:
|
| 58 |
+
# Header
|
| 59 |
+
with gr.Row():
|
| 60 |
+
gr.Image(GRAVATAR_URL, shape=(100,100), tooltips="Sky Meilin", interactive=True)
|
| 61 |
+
gr.Markdown(f"## 🔥 Anycoder 30de8a5b – Conversational Program Synthesis\n**Sky Meilin** – [Gravatar Profil]({GRAVATAR_LINK})")
|
| 62 |
+
|
| 63 |
+
# Input
|
| 64 |
+
prompt_input = gr.Textbox(label="Beschreibung oder Code eingeben", placeholder="Z.B. 'Sortiere eine Liste...'", lines=8)
|
| 65 |
+
|
| 66 |
+
# Finger Buttons
|
| 67 |
+
output_code = gr.Textbox(label="Ergebnis", lines=10)
|
| 68 |
+
with gr.Row():
|
| 69 |
+
for name, func in fingers.items():
|
| 70 |
+
gr.Button(name).click(func, inputs=prompt_input, outputs=output_code)
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
app.launch()
|
| 74 |
+
|