kevalfst commited on
Commit
507a2aa
·
verified ·
1 Parent(s): 0510a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,22 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load model (you can change this to your own)
5
- generator = pipeline("text2text-generation", model="google/flan-t5-base")
6
 
7
- # Function to generate code from prompt
8
- def generate_code(prompt):
9
- result = generator(prompt, max_new_tokens=100)[0]["generated_text"]
 
 
 
 
 
 
 
10
  return result.strip()
11
 
12
- # Gradio UI and API Interface
13
  iface = gr.Interface(
14
- fn=generate_code,
15
- inputs=gr.Textbox(label="Enter prompt (e.g., Describe code)"),
16
- outputs=gr.Textbox(label="Generated Code"),
17
- title="Code Generator AI",
18
- description="This app generates code based on your prompt. You can use it from the browser or call it via API."
19
  )
20
 
21
- # Launch Space (UI + API mode enabled)
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)