Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load model
|
5 |
-
generator = pipeline("
|
6 |
|
7 |
-
#
|
8 |
-
def
|
9 |
-
result = generator(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return result.strip()
|
11 |
|
12 |
-
# Gradio UI and API
|
13 |
iface = gr.Interface(
|
14 |
-
fn=
|
15 |
-
inputs=gr.Textbox(
|
16 |
-
outputs=gr.Textbox(label="
|
17 |
-
title="Code
|
18 |
-
description="
|
19 |
)
|
20 |
|
21 |
-
#
|
22 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load code-aware model
|
5 |
+
generator = pipeline("text-generation", model="microsoft/phi-1_5")
|
6 |
|
7 |
+
# Code assistant function
|
8 |
+
def generate_from_code(prompt):
|
9 |
+
result = generator(
|
10 |
+
prompt,
|
11 |
+
max_new_tokens=256,
|
12 |
+
do_sample=True,
|
13 |
+
temperature=0.7,
|
14 |
+
pad_token_id=generator.tokenizer.eos_token_id
|
15 |
+
)[0]["generated_text"]
|
16 |
+
|
17 |
return result.strip()
|
18 |
|
19 |
+
# Gradio app with UI and API mode
|
20 |
iface = gr.Interface(
|
21 |
+
fn=generate_from_code,
|
22 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste code or describe what to do...", label="Prompt / Code"),
|
23 |
+
outputs=gr.Textbox(label="AI Output"),
|
24 |
+
title="AI Code Helper",
|
25 |
+
description="Give a prompt, code snippet, or question. Example: 'Explain this code', 'Complete this function', or 'Fix the bug'."
|
26 |
)
|
27 |
|
28 |
+
# Enable public API
|
29 |
+
iface.launch(share=True)
|