ai-code-helper / app.py
mshary55's picture
app.py
11762dd verified
raw
history blame contribute delete
917 Bytes
import gradio as gr
import requests
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
headers = {"Authorization": "Bearer hfhf_xwRkmUBKVOLNhzKVSSXPbvrecfJeaEmPzY"}
def generate_code(prompt):
payload = {"inputs": prompt, "parameters": {"max_new_tokens": 200}}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
return result[0]['generated_text']
else:
return "حدث خطأ أثناء توليد الكود"
interface = gr.Interface(
fn=generate_code,
inputs=gr.Textbox(lines=5, placeholder="اكتب وصف الكود الذي تريده..."),
outputs="text",
title="مساعد ذكاء اصطناعي للبرمجة",
description="هذا الذكاء الاصطناعي سيساعدك على كتابة الأكواد تلقائيًا!"
)
interface.launch()