Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Edu-App Architect", page_icon="🎓")
|
| 6 |
+
st.title("🎓 Edu-App Architect")
|
| 7 |
+
st.markdown("Descrivi l'app didattica che vuoi. L'AI scriverà il codice per te.")
|
| 8 |
+
|
| 9 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 10 |
+
if not hf_token:
|
| 11 |
+
st.error("ERRORE: Manca il token. Vai in Settings -> Variables and secrets e aggiungi 'HF_TOKEN'.")
|
| 12 |
+
st.stop()
|
| 13 |
+
|
| 14 |
+
client = InferenceClient(api_key=hf_token)
|
| 15 |
+
|
| 16 |
+
prompt = st.text_area("Cosa vuoi creare?", height=150, placeholder="Es: Un quiz sui verbi italiani.")
|
| 17 |
+
generate_btn = st.button("🚀 Genera Codice", type="primary")
|
| 18 |
+
|
| 19 |
+
if generate_btn and prompt:
|
| 20 |
+
with st.spinner("L'Architetto sta lavorando..."):
|
| 21 |
+
try:
|
| 22 |
+
messages = [
|
| 23 |
+
{"role": "system", "content": "Sei un esperto sviluppatore Python Streamlit. Scrivi SOLO il codice completo per un'app funzionante. Nessuna spiegazione, solo codice. Inizia con 'import streamlit as st'."},
|
| 24 |
+
{"role": "user", "content": f"Crea un'app Streamlit completa che faccia questo: {prompt}"}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
response = client.chat_completion(
|
| 28 |
+
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 29 |
+
messages=messages,
|
| 30 |
+
max_tokens=2000,
|
| 31 |
+
temperature=0.5
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
code = response.choices[0].message.content
|
| 35 |
+
code = code.replace("```python", "").replace("```", "").strip()
|
| 36 |
+
|
| 37 |
+
st.success("Codice Generato! Copia e incolla in un nuovo file app.py")
|
| 38 |
+
st.code(code, language="python")
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"Errore: {e}")
|