Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load ChatGPT model (or use Hugging Face API)
|
| 5 |
+
generator = pipeline("text-generation", model="gpt-3.5-turbo")
|
| 6 |
+
|
| 7 |
+
# Function to generate code
|
| 8 |
+
def generate_code(microcontroller, project, custom_input):
|
| 9 |
+
prompt = f"Generate {microcontroller} code for a {project} project. {custom_input}"
|
| 10 |
+
response = generator(prompt, max_length=500)
|
| 11 |
+
return response[0]["generated_text"]
|
| 12 |
+
|
| 13 |
+
# Gradio interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=generate_code,
|
| 16 |
+
inputs=[
|
| 17 |
+
gr.Dropdown(["Arduino", "ESP32", "STM32"], label="Microcontroller"),
|
| 18 |
+
gr.Dropdown(["LED Blinking", "Sensor Integration", "Motor Control"], label="Project Type"),
|
| 19 |
+
gr.Textbox(label="Custom Input (e.g., Pin Numbers, Delays)")
|
| 20 |
+
],
|
| 21 |
+
outputs=gr.Textbox(label="Generated Code"),
|
| 22 |
+
title="Embedded System Code Generator",
|
| 23 |
+
description="Automatically generate embedded system code for common microcontroller-based projects."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|