Spaces:
Sleeping
Sleeping
File size: 917 Bytes
11762dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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() |