miiann commited on
Commit
fb2e956
·
verified ·
1 Parent(s): 05f60f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -1,30 +1,36 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Stable configuration for CPU
5
- model = pipeline(
6
- "text-generation",
7
- model="bigcode/tiny_starcoder_py",
8
- device="cpu"
9
- )
 
 
 
 
10
 
11
- def generate_code(prompt):
12
  try:
13
  response = model(
14
- f"# Question\n{prompt}\n# Answer\n",
15
- max_new_tokens=80,
16
- temperature=0.3,
17
- do_sample=False
18
  )
19
- return response[0]['generated_text'].split("# Answer\n")[-1]
20
  except Exception as e:
21
  return f"Error: {str(e)}"
22
 
23
- demo = gr.Interface(
24
- fn=generate_code,
25
- inputs=gr.Textbox(lines=2, placeholder="Ask about Python..."),
26
- outputs=gr.Code(language="python"),
27
- title="Stable Coding Assistant"
 
 
28
  )
29
 
30
- demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Minimal stable configuration
5
+ def load_model():
6
+ return pipeline(
7
+ "text-generation",
8
+ model="distilgpt2", # Smallest reliable model
9
+ device="cpu",
10
+ framework="pt"
11
+ )
12
+
13
+ model = load_model()
14
 
15
+ def generate_text(prompt):
16
  try:
17
  response = model(
18
+ prompt,
19
+ max_length=50,
20
+ temperature=0.7,
21
+ num_return_sequences=1
22
  )
23
+ return response[0]['generated_text']
24
  except Exception as e:
25
  return f"Error: {str(e)}"
26
 
27
+ # Basic interface
28
+ iface = gr.Interface(
29
+ fn=generate_text,
30
+ inputs=gr.Textbox(lines=2, placeholder="Enter your prompt..."),
31
+ outputs=gr.Textbox(),
32
+ title="Stable Text Generator",
33
+ description="Basic but guaranteed-to-work version"
34
  )
35
 
36
+ iface.launch(server_name="0.0.0.0")