Spaces:
Configuration error
Configuration error
| import gradio as gr | |
| from huggingface_hub import InferenceApi | |
| # No token passed—using public endpoint | |
| inference = InferenceApi(repo_id="bigcode/starcoderbase") | |
| def generate_code(prompt): | |
| try: | |
| output = inference({"inputs": f"'''\n# Task: {prompt}\n'''"}) | |
| # output may be dict or string | |
| if isinstance(output, dict) and "generated_text" in output: | |
| return output["generated_text"] | |
| return output if isinstance(output, str) else str(output) | |
| except Exception as e: | |
| return f"Error: {e}" | |
| demo = gr.Interface( | |
| fn=generate_code, | |
| inputs=gr.Textbox(lines=2, placeholder="Describe coding task..."), | |
| outputs="text", | |
| title="CodeM8 AI (public)", | |
| description="Generate or explain code; no token needed." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |