Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
5 |
+
headers = {"Authorization": "Bearer hfhf_xwRkmUBKVOLNhzKVSSXPbvrecfJeaEmPzY"}
|
6 |
+
|
7 |
+
def generate_code(prompt):
|
8 |
+
payload = {"inputs": prompt, "parameters": {"max_new_tokens": 200}}
|
9 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
10 |
+
if response.status_code == 200:
|
11 |
+
result = response.json()
|
12 |
+
return result[0]['generated_text']
|
13 |
+
else:
|
14 |
+
return "حدث خطأ أثناء توليد الكود"
|
15 |
+
|
16 |
+
interface = gr.Interface(
|
17 |
+
fn=generate_code,
|
18 |
+
inputs=gr.Textbox(lines=5, placeholder="اكتب وصف الكود الذي تريده..."),
|
19 |
+
outputs="text",
|
20 |
+
title="مساعد ذكاء اصطناعي للبرمجة",
|
21 |
+
description="هذا الذكاء الاصطناعي سيساعدك على كتابة الأكواد تلقائيًا!"
|
22 |
+
)
|
23 |
+
|
24 |
+
interface.launch()
|